Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modernizing Legacy Code Step by Step

Joe Ferguson
November 16, 2018

Modernizing Legacy Code Step by Step

We’ll be taking a real PHP 5.2 codebase and migrating it to the latest and greatest PHP version. We’ll cover refactoring, adding components to handle routing, database access, as well as converting our HTML output to views. We’ll step through the entire process to demonstrate a repeatable solution for modernizing your legacy application!

Joe Ferguson

November 16, 2018
Tweet

More Decks by Joe Ferguson

Other Decks in Technology

Transcript

  1. Who Am I? Joe Ferguson PHP Developer PHP Architect @

    Ministry Brands Twitter: @JoePFerguson OSMI Board Member Drone Racing Pilot
  2. Initial Project Overview Is there a framework? Is there a

    coding standard? Is there any autoloading? How are dependencies behind handled? Is there an ORM or how is the database being utilized? Is there a development environment?
  3. Triage Address any critical things found PHP Short Tags! PHP

    version issues Current server is 5.2 lets test 7.2 Fixing critical vulnerabilities
  4. Why not rewrite? Progress halts entirely Business logic is rarely

    reused Most of the time is getting back to current functionality
  5. Existing Tests This is great! Review the tests to get

    an idea of coverage Passing tests become your control for any upcoming changes Confidence++
  6. No Existing Tests Not the end of the world! Inspect

    the code base, was it written to be easily testable? Could you easily mock dependencies?
  7. Untestable Code Not all code is testable If you can’t

    easily unit test the code base, consider alternatives Functional testing and Acceptance testing are valid options
  8. Acceptance Testing NOT a replacement for Unit Testing Test large

    parts of your application at a time Can be harder to pinpoint error location Gives large code coverage in short amount of time
  9. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests Extract SQL (to ORM or other)
  10. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests Extract SQL (to ORM or other) Extract Business Logic (To domain logic)
  11. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests Extract SQL (to ORM or other) Extract Business Logic (To domain logic) Extract Presentation Logic to Views (Twig, Blade, etc)
  12. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests Extract SQL (to ORM or other) Extract Business Logic (To domain logic) Extract Presentation Logic to Views (Twig, Blade, etc) Extract Action Logic (To Controllers)
  13. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests Extract SQL (to ORM or other) Extract Business Logic (To domain logic) Extract Presentation Logic to Views (Twig, Blade, etc) Extract Action Logic (To Controllers) Write (more) tests
  14. Resources / Q & A Modernizing Legacy Applications In PHP

    - Paul M. Jones https://leanpub.com/mlaphp Minimum Viable Tests - Chris Hartjes https://leanpub.com/minimumviabletests Code Style https://github.com/FriendsOfPHP/PHP-CS-Fixer, http://editorconfig.org php mess detector https://phpmd.org Autoloading PSR-4 https://getcomposer.org/doc/01-basic-usage.md ORMs http://www.doctrine-project.org http://propelorm.org Docker https://leanpub.com/dockerfordevs, Vagrant https://puphpet.com