Dragging Old Frameworks Into the Future With Limited Kicking and Screaming

Dragging Old Frameworks Into the Future With Limited Kicking and Screaming

Joe's career has been filled with legacy projects he's been tasked with bringing into the modern PHP world. He'll share experiences specifically with refactoring a Kohana framework project and the steps his team is taking to modernize the code base while introducing new features and continuing to deliver releases for their customers. Join us as we learn about dragging old legacy projects into the future of modern PHP development without much kicking and screaming.

Fef6ec2170ad1ecfcacdf2ead305f040?s=128

Joe Ferguson

May 31, 2018
Tweet

Transcript

  1. Dragging Old Frameworks Into the Future With Limited Kicking and

    Screaming Joe Ferguson May 31st 2018
  2. Who Am I? Joe Ferguson PHP Developer PHP Architect @

    Ministry Brands Twitter: @JoePFerguson OSMI Board Member Drone Racing Pilot
  3. For Further Reading leanpub.com/mlaphp leanpub.com/minimumviabletests

  4. Legacy Applications

  5. “There are no solutions, only trade offs” - Joe Ferguson

    - Paul M. Jones - Thomas Sowell
  6. Taking stock of what we’re working with

  7. 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?
  8. Is there a framework?

  9. Is there a coding standard?

  10. No Standard? No problem!

  11. Is there any autoloading?

  12. There is a PSR for that…

  13. How are dependencies behind handled?

  14. Is there an ORM or how is the database being

    utilized?
  15. Tools to help

  16. PHP Coding Standards Fixer http://cs.sensiolabs.org/

  17. PHP Coding Standards Fixer php-cs-fixer fix app --dry-run

  18. PHP Mess Detector https://phpmd.org

  19. PHP Mess Detector https://phpmd.org $ phpmd app html cleancode --reportfile

    report.html
  20. Warning about Automating Code Changes

  21. Composer https://getcomposer.org/doc/01-basic-usage.md

  22. Triage Address any critical things found PHP version issues Fixing

    critical vulnerabilities
  23. “We should just rewrite the app”

  24. "This would be so much easier in framework _____________”

  25. Why not rewrite? Progress halts entirely Business logic is rarely

    reused Most of the time is getting back to current functionality
  26. Why you should refactor Progress continues Business logic reused Modernizing

    functionality instead of recreating
  27. Existing Tests This is great! Review the tests to get

    an idea of coverage Passing tests become your control for any upcoming changes Confidence++
  28. 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?
  29. 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
  30. 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
  31. Digging into the Code Code Consolidation

  32. Code Consolidation

  33. Code Consolidation

  34. _config_vars.php

  35. _db_connect.php

  36. composer require vlucas/phpdotenv

  37. Database Class

  38. Progress

  39. header.php

  40. Digging into the Code Code Consolidation Replace globals with DI

  41. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests
  42. Digging into the Code Code Consolidation Replace globals with Dependency

    Injection Write tests Extract SQL (to ORM or other)
  43. 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)
  44. _functions.php

  45. Weather Class

  46. Refactoring index.php

  47. header.php

  48. 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)
  49. 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)
  50. 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
  51. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config

  52. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config

  53. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config

  54. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config

  55. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config

  56. Logging https://github.com/mattstauffer/Torch/tree/master/components/log

  57. Logging https://github.com/mattstauffer/Torch/tree/master/components/log

  58. Logging

  59. Logging

  60. You’ll likely want to configure your logger into a base

    class that is extended
  61. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing

  62. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing

  63. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing

  64. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing

  65. Routing

  66. Routing

  67. Database https://github.com/mattstauffer/Torch/tree/master/components/database

  68. Database https://github.com/mattstauffer/Torch/tree/master/components/database

  69. Database https://github.com/mattstauffer/Torch/tree/master/components/database

  70. Database https://github.com/mattstauffer/Torch/tree/master/components/database

  71. Container https://github.com/mattstauffer/Torch/tree/master/components/container

  72. Container https://github.com/mattstauffer/Torch/tree/master/components/container

  73. Container https://github.com/mattstauffer/Torch/tree/master/components/container

  74. Container https://github.com/mattstauffer/Torch/tree/master/components/container

  75. Container https://github.com/mattstauffer/Torch/tree/master/components/container

  76. Container https://github.com/mattstauffer/Torch/tree/master/components/container

  77. Containers are very powerful. Make sure you’re not adding spaghetti

    code just to shoehorn into your App
  78. 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
  79. Joe Ferguson Twitter: @JoePFerguson Email: joe@joeferguson.me Freenode: joepferguson Contact Info:

    https://joind.in/talk/c2815