You were just handed the keys to a new repo. Your first glance over the code base causes the fearful “LEGACY” word to ring in your head. HAVE NO FEAR! I’ll share the techniques I’ve learned after working on several legacy codebases to help update that old code to the current PHP generation. We’ll cover triaging the old code base, writing tests to make sure you don’t break anything, and how to modernize your old code base!
So You Just Inherited a $Legacy Application… NomadPHP July 2016
1. So You Just Inherited a
$Legacy Application...
https://legacy.joind.in/18603
Joe Ferguson
2. Who Am I?
Joe Ferguson
PHP Developer
Engineer @ Aol.
Twitter: @JoePFerguson
Organizer of @MemphisPHP
@NomadPHP Lightning Talks
Passionate about Community
8. Legacy is often used for an older production
application that was written before, or without
regard for modern technologies or practices.
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. Modern Interpretation
"... source code inherited from someone else …"
"... source code inherited from an older version of the software ..."
11. Some people say…
"Any code in production is not legacy”
"Any code written X years ago is legacy"
12. Legacy is all these things
As we talk about Legacy code here,
we're really talking about all of these definitions
14. Inheriting a Legacy App
Precontemplation or Shock/Disbelief
Contemplation and/or Anger
Determination and Bargaining
Action and Reconstruction
Maintenance and Acceptance
18. Precontemplation
Not ready for change (project, code base, etc)
Usually you don’t know the depths of issues
Can sometimes lead to assuming the worst
Usually this is the shortest phase due to business needs
19. Shock/Disbelief
This is where the WTFs and the WTHs should be left
Try to work through any negativity here
Be positive about the previous developer’s intentions
24. 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?
52. No Question Left Behind!
The application has no framework, We’re going to use a micro
framework as we refactor.
The application has no autoloading, But we’re using Composer
Dependencies are checked into version control, But we’re using
Composer
There is no ORM, but we’re going to use Propel
We have no dev environment but we’re going to use Vagrant
53. Proof of Concept
Any new things introduced should be tested to ensure
functionality
Build out a small example of an area you or the team doesn't fully
comprehend so you can address any questions that may arise
54. Bargaining
Getting stakeholders on board with your estimates
Do the decisions made thus far make business sense?
Are there any doubts in the plan?
61. Existing Tests
This is great!
Review the tests to get an idea of coverage
Passing tests become your control for any upcoming changes
Confidence++
62. 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?
63. 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
64. 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