so you just inherited a $legacy application… nomadphp july 2016
TRANSCRIPT
![Page 1: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/1.jpg)
So You Just Inherited a $Legacy Application...
https://legacy.joind.in/18603
Joe Ferguson
![Page 2: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/2.jpg)
Who Am I?
Joe Ferguson
PHP Developer
Engineer @ Aol.
Twitter: @JoePFerguson
Organizer of @MemphisPHP
@NomadPHP Lightning Talks
Passionate about Community
![Page 3: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/3.jpg)
For Further Reading
leanpub.com/mlaphpleanpub.com/minimumviabletests
![Page 4: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/4.jpg)
Legacy Applications
![Page 5: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/5.jpg)
First: A Warning
![Page 6: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/6.jpg)
“There are no solutions, only trade offs”
- Joe Ferguson
- Paul M. Jones
- Thomas Sowell
![Page 7: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/7.jpg)
What is a "Legacy" application
![Page 8: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/8.jpg)
Legacy is often used for an older production application that was written before, or without regard for modern technologies or practices.
![Page 9: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/9.jpg)
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
![Page 10: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/10.jpg)
Modern Interpretation
"... source code inherited from someone else …"
"... source code inherited from an older version of the software ..."
![Page 11: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/11.jpg)
Some people say…
"Any code in production is not legacy”
"Any code written X years ago is legacy"
![Page 12: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/12.jpg)
Legacy is all these things
As we talk about Legacy code here, we're really talking about all of these definitions
![Page 13: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/13.jpg)
This process is not Legacy Specific…
![Page 14: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/14.jpg)
Inheriting a Legacy App
Precontemplation or Shock/Disbelief
Contemplation and/or Anger
Determination and Bargaining
Action and Reconstruction
Maintenance and Acceptance
![Page 15: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/15.jpg)
Precontemplation or Shock/Disbelief
![Page 16: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/16.jpg)
This is the initial "what is this?!"
![Page 17: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/17.jpg)
That’s now how this works!
![Page 18: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/18.jpg)
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
![Page 19: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/19.jpg)
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
![Page 20: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/20.jpg)
Contemplation and/or Anger
![Page 21: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/21.jpg)
This is the planning phase
![Page 22: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/22.jpg)
Try to get all of your ager at the code base out during this phase, it will help
you see the path forward.
![Page 23: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/23.jpg)
Taking stock of what we’re working with
![Page 24: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/24.jpg)
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?
![Page 25: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/25.jpg)
Is there a framework?
![Page 26: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/26.jpg)
Is there a coding standard?
![Page 27: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/27.jpg)
No Standard? No problem!
![Page 28: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/28.jpg)
Is there any autoloading?
![Page 29: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/29.jpg)
There is a PSR for that…
![Page 30: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/30.jpg)
How are dependencies behind handled?
![Page 31: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/31.jpg)
Is there an ORM or how is the database being utilized?
![Page 32: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/32.jpg)
Is there a development environment?
![Page 33: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/33.jpg)
Tools to help
![Page 34: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/34.jpg)
PHP Coding Standards Fixerhttp://cs.sensiolabs.org/
![Page 35: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/35.jpg)
PHP Coding Standards Fixerphp-cs-fixer fix app --dry-run
![Page 36: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/36.jpg)
PHP Mess Detectorhttps://phpmd.org
![Page 37: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/37.jpg)
PHP Mess Detectorhttps://phpmd.org
$ phpmd app html cleancode --reportfile report.html
![Page 38: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/38.jpg)
Warning about Automating Code Changes
![Page 40: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/40.jpg)
Doctrinehttp://www.doctrine-project.org
![Page 42: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/42.jpg)
Local Dev Environments
Physical Hardware
Vagrant (Virtual Machines)
Docker (Containers)
![Page 43: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/43.jpg)
Physical Hardware
![Page 44: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/44.jpg)
Vagrant
![Page 45: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/45.jpg)
PuPHPet.com
![Page 46: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/46.jpg)
![Page 48: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/48.jpg)
Determination and BargainingDecision making and triage time
![Page 49: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/49.jpg)
Triage
Address any critical things found in Contemplation phase
PHP version issues
Fixing critical vulnerabilities
![Page 50: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/50.jpg)
You have a plan and now you need to estimate this plan.
![Page 51: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/51.jpg)
I hate estimating
nomadphp.com/2016/04/06/stop-multiplying-4/
Lightning talk by Chuck Reeves (@manchuck)
Short and sweet talk about how to do better estimating
![Page 52: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/52.jpg)
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
![Page 53: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/53.jpg)
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
![Page 54: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/54.jpg)
Bargaining
Getting stakeholders on board with your estimates
Do the decisions made thus far make business sense?
Are there any doubts in the plan?
![Page 55: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/55.jpg)
“We should just rewrite the app”
![Page 56: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/56.jpg)
"This would be so much easier in framework _____________”
![Page 57: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/57.jpg)
Why not rewrite?
Progress halts entirely
Business logic is rarely reused
Most of the time is getting back to current functionality
![Page 58: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/58.jpg)
Why you should refactor
Progress continues
Business logic reused
Modernizing functionality instead of recreating
![Page 59: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/59.jpg)
Make Decisions
Build Proof of Concept(s)
Ensure stakeholder buy in
Avoid the allure of green fields**
** in some cases a rewrite is warranted
![Page 60: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/60.jpg)
Action and Reconstruction
![Page 61: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/61.jpg)
Existing Tests
This is great!
Review the tests to get an idea of coverage
Passing tests become your control for any upcoming changes
Confidence++
![Page 62: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/62.jpg)
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?
![Page 63: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/63.jpg)
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
![Page 64: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/64.jpg)
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
![Page 65: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/65.jpg)
Digging into the Code
Code Consolidation
![Page 66: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/66.jpg)
Digging into the Code
Code Consolidation
Replace globals with DI
![Page 67: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/67.jpg)
Digging into the Code
Code Consolidation
Replace globals with Dependency Injection
Write tests
![Page 68: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/68.jpg)
Digging into the Code
Code Consolidation
Replace globals with Dependency Injection
Write tests
Extract SQL (to ORM or other)
![Page 69: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/69.jpg)
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)
![Page 70: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/70.jpg)
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)
![Page 71: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/71.jpg)
Digging into the CodeCode 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)
![Page 72: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/72.jpg)
Digging into the CodeCode 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
![Page 73: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/73.jpg)
Maintenance and Acceptance
![Page 74: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/74.jpg)
Maintenance and AcceptanceCode 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
![Page 75: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/75.jpg)
Maintenance and Acceptance
Adding Features
More New Code
Less Refactoring
Maintain your processes
![Page 76: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/76.jpg)
Continuous Integration
![Page 77: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/77.jpg)
Revisit Acceptance Tests
![Page 78: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/78.jpg)
Resources / Q & AModernizing 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
![Page 79: So You Just Inherited a $Legacy Application… NomadPHP July 2016](https://reader036.vdocuments.us/reader036/viewer/2022062900/58e985791a28aba6498b5b33/html5/thumbnails/79.jpg)
Feedback!
https://legacy.joind.in/18603
Joe FergusonTwitter: @JoePFergusonEmail: [email protected]: joepferguson
Contact Info: