Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Throwing Laravel into your Legacy App™

1,102 views

Published on

Do you work on a legacy application and yearn for the green fields and bountiful structure of an application built on a modern framework? Do you feel like the only path to modernizing your old workhorse app is to spend months or years rewriting it from the ground up? What if you could integrate modern packages from a full stack framework at your own pace instead of having to start over from scratch? Join us as we explore using Laravel components in your Legacy App™. Modernize how your application handles configuration, routing, container, database, and much more!

Published in: Software
  • Be the first to comment

Throwing Laravel into your Legacy App™

  1. 1. Throwing Laravel into your Legacy™ Application Joe Ferguson
  2. 2. Who Am I? Joe Ferguson PHP Developer PHP Architect @ Ministry Brands Twitter: @JoePFerguson Organizer of @MemphisPHP @NomadPHP Lightning Talks Drone Racing Pilot
  3. 3. For Further Reading leanpub.com/mlaphplaravelupandrunning.com
  4. 4. First: A Warning
  5. 5. Legacy Applications
  6. 6. “There are no solutions, only trade offs” - Joe Ferguson - Paul M. Jones - Thomas Sowell
  7. 7. What is a "Legacy" application
  8. 8. Legacy is often used for an older production application that was written before, or without regard for modern technologies or practices.
  9. 9. If you ask Wikipedia… "... no-longer supported …" "... maintained by an administrator that did not develop the code …" "... supporting older file formats ..." https://en.wikipedia.org/wiki/Legacy_code
  10. 10. Modern Interpretation "... source code inherited from someone else …" "... source code inherited from an older version of the software ..."
  11. 11. Some people say… "Any code in production is not legacy” "Any code written X years ago is legacy"
  12. 12. Legacy is all these things As we talk about Legacy code here, we're really talking about all of these definitions
  13. 13. This process is not Legacy Specific…
  14. 14. 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?
  15. 15. Is there a framework?
  16. 16. Is there a coding standard?
  17. 17. There is a PSR for that…
  18. 18. How are dependencies behind handled?
  19. 19. Is there an ORM or how is the database being utilized?
  20. 20. Tools to help
  21. 21. PHP Coding Standards Fixer http://cs.sensiolabs.org/
  22. 22. PHP Coding Standards Fixer php-cs-fixer fix app --dry-run
  23. 23. PHP Mess Detector https://phpmd.org
  24. 24. PHP Mess Detector https://phpmd.org $ phpmd app html cleancode --reportfile report.html
  25. 25. Warning about Automating Code Changes
  26. 26. Triage Address any critical things found in Contemplation phase PHP version issues Fixing critical vulnerabilities
  27. 27. “We should just rewrite the app”
  28. 28. "This would be so much easier in framework _____________”
  29. 29. Why not rewrite? Progress halts entirely Business logic is rarely reused Most of the time is getting back to current functionality
  30. 30. Why you should refactor Progress continues Business logic reused Modernizing functionality instead of recreating
  31. 31. Make Decisions Build Proof of Concept(s) Ensure stakeholder buy in Avoid the allure of green fields** ** in some cases a rewrite is warranted Refactoring Approach
  32. 32. Existing Tests This is great! Review the tests to get an idea of coverage Passing tests become your control for any upcoming changes Confidence++
  33. 33. 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?
  34. 34. 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
  35. 35. 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
  36. 36. Digging into the Code Code Consolidation
  37. 37. Digging into the Code Code Consolidation Replace globals with DI
  38. 38. Digging into the Code Code Consolidation Replace globals with Dependency Injection Write tests
  39. 39. Digging into the Code Code Consolidation Replace globals with Dependency Injection Write tests Extract SQL (to ORM or other)
  40. 40. 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)
  41. 41. 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)
  42. 42. 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)
  43. 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) Extract Presentation Logic to Views (Twig, Blade, etc) Extract Action Logic (To Controllers) Write (more) tests
  44. 44. Continuous Integration
  45. 45. Where does Laravel fit in?
  46. 46. You can easily** use Laravel components in your Legacy App ** Relatively speaking, and not all components
  47. 47. Laravel Component Goals Implement Configuration Implement Logging Implement Routing Implement Database Implement Container
  48. 48. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config
  49. 49. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config
  50. 50. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config
  51. 51. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config
  52. 52. Configuration https://github.com/mattstauffer/Torch/tree/master/components/config
  53. 53. What about secrets? composer require vlucas/phpdotenv
  54. 54. composer require vlucas/phpdotenv .env config/app.php
  55. 55. Access Config the same way
  56. 56. Now our config is outside VCS
  57. 57. Do NOT version control your .env file!
  58. 58. Logging https://github.com/mattstauffer/Torch/tree/master/components/log
  59. 59. Logging https://github.com/mattstauffer/Torch/tree/master/components/log
  60. 60. Logging
  61. 61. Logging
  62. 62. You’ll likely want to configure your logger into a base class that is extended
  63. 63. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing
  64. 64. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing
  65. 65. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing
  66. 66. Routing https://github.com/mattstauffer/Torch/tree/master/components/routing
  67. 67. Routing
  68. 68. Routing
  69. 69. Database https://github.com/mattstauffer/Torch/tree/master/components/database
  70. 70. Database https://github.com/mattstauffer/Torch/tree/master/components/database
  71. 71. Database https://github.com/mattstauffer/Torch/tree/master/components/database
  72. 72. Database https://github.com/mattstauffer/Torch/tree/master/components/database
  73. 73. Container https://github.com/mattstauffer/Torch/tree/master/components/container
  74. 74. Container https://github.com/mattstauffer/Torch/tree/master/components/container
  75. 75. Container https://github.com/mattstauffer/Torch/tree/master/components/container
  76. 76. Container https://github.com/mattstauffer/Torch/tree/master/components/container
  77. 77. Container https://github.com/mattstauffer/Torch/tree/master/components/container
  78. 78. Container https://github.com/mattstauffer/Torch/tree/master/components/container
  79. 79. Containers are very powerful. Make sure you’re not adding spaghetti code just to shoehorn into your App
  80. 80. Recap Follow a refactoring process Leverage Laravel components as you refactor Make sure you write tests along the way!
  81. 81. Joe Ferguson Twitter: @JoePFerguson Email: joe@joeferguson.me Freenode: joepferguson Contact Info: https://joind.in/talk/d306e Feedback:

×