joind.in/talk/228f1
@SammyK #pnwphp
Refactoring
Martin Fowler
http://martinfowler.com/books/refactoring.html
Slide 17
Slide 17 text
joind.in/talk/228f1
@SammyK #pnwphp
“Legacy”
/leɡəsē/
• Requires an EOL version of PHP
• No automated tests
• Has outdated dependencies
• No autoloading
• No sign of “single responsibility”
Slide 18
Slide 18 text
joind.in/talk/228f1
@SammyK #pnwphp
Slide 19
Slide 19 text
joind.in/talk/228f1
@SammyK #pnwphp
“Legacy”
We’ll assume
…means any code that is
running on PHP 5.x
(at least for this talk)
Slide 20
Slide 20 text
joind.in/talk/228f1
@SammyK #pnwphp
Expectations
Slide 21
Slide 21 text
joind.in/talk/228f1
@SammyK #pnwphp
elePHPant
How to eat an
Slide 22
Slide 22 text
joind.in/talk/228f1
@SammyK #pnwphp
ZERO
Step
Slide 23
Slide 23 text
joind.in/talk/228f1
@SammyK #pnwphp
Around
Poke
Slide 24
Slide 24 text
joind.in/talk/228f1
@SammyK #pnwphp
Around
Poke
• Composer &/or autoloading?
• Documentation? (Look for hidden docs!)
• Framework/Dependencies? (How out-dated?)
• How is database layer implemented?
• How is config handled?
• How are front-end assets handled?
• Are there tests?
• Production env (PHP version)
joind.in/talk/228f1
@SammyK #pnwphp
Consider the
Stakeholders
Slide 30
Slide 30 text
joind.in/talk/228f1
@SammyK #pnwphp
Consider the Stakeholders
I’ll need 80
hours to
refactor the
user auth & ACL
Slide 31
Slide 31 text
joind.in/talk/228f1
@SammyK #pnwphp
Consider the Stakeholders
• Most critical security holes
• Most critical bugs
• Most critical features
• Use data from static analysis
Make a plan
Slide 32
Slide 32 text
joind.in/talk/228f1
@SammyK #pnwphp
ONE
Step
Slide 33
Slide 33 text
joind.in/talk/228f1
@SammyK #pnwphp
5.(wat)
Get it running on
Slide 34
Slide 34 text
Environment
Get it running on your local
Slide 35
Slide 35 text
joind.in/talk/228f1
@SammyK #pnwphp
Git with an
SCM
Slide 36
Slide 36 text
joind.in/talk/228f1
@SammyK #pnwphp
Slide 37
Slide 37 text
joind.in/talk/228f1
@SammyK #pnwphp
Git
Get with
master
original
local-config
Slide 38
Slide 38 text
joind.in/talk/228f1
@SammyK #pnwphp
Fix all the errors
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
joind.in/talk/228f1
@SammyK #pnwphp
TWO
Step
Slide 41
Slide 41 text
joind.in/talk/228f1
@SammyK #pnwphp
7.1
Get it running on
Slide 42
Slide 42 text
joind.in/talk/228f1
@SammyK #pnwphp
PHP 7.0
Is almost
2 years old!
Slide 43
Slide 43 text
joind.in/talk/228f1
@SammyK #pnwphp
2
Slide 44
Slide 44 text
joind.in/talk/228f1
@SammyK #pnwphp
years
Slide 45
Slide 45 text
joind.in/talk/228f1
@SammyK #pnwphp
old!
Slide 46
Slide 46 text
joind.in/talk/228f1
@SammyK #pnwphp
OLD
Slide 47
Slide 47 text
joind.in/talk/228f1
@SammyK #pnwphp
http://php.net/supported-versions.php
> 3 months
Active support (bug fixes) for PHP 7.0 ends
Slide 48
Slide 48 text
joind.in/talk/228f1
@SammyK #pnwphp
OLD
PHP 7.0 is
Slide 49
Slide 49 text
7.1
✓Performance
increase
PHP 7
features
✓
Slide 50
Slide 50 text
7.1
Slide 51
Slide 51 text
BC
is totes amaze
Slide 52
Slide 52 text
joind.in/talk/228f1
@SammyK #pnwphp
PHP 7 enlightenment
The path to
7.1
5.6
Slide 53
Slide 53 text
joind.in/talk/228f1
@SammyK #pnwphp
7.1
5.5
PHP 7 enlightenment
The path to
Slide 54
Slide 54 text
joind.in/talk/228f1
@SammyK #pnwphp
7.1
5.4
PHP 7 enlightenment
The path to
Slide 55
Slide 55 text
joind.in/talk/228f1
@SammyK #pnwphp
7.1
<= 5.3
PHP 7 enlightenment
The path to
Slide 56
Slide 56 text
joind.in/talk/228f1
@SammyK #pnwphp
THREE
Step
Slide 57
Slide 57 text
joind.in/talk/228f1
@SammyK #pnwphp
Fix all the PHP 7 errors
Slide 58
Slide 58 text
joind.in/talk/228f1
@SammyK #pnwphp
PHP 7
Quick tricks to refactor to
(in order of ease)
Slide 59
Slide 59 text
joind.in/talk/228f1
@SammyK #pnwphp
PHP 7.0 “Gotchas”
ASP and
PHP
tags removed
joind.in/talk/228f1
@SammyK #pnwphp
5.x
string(16) "PHP 5.x I see..."
Slide 87
Slide 87 text
joind.in/talk/228f1
@SammyK #pnwphp
7.x
Slide 88
Slide 88 text
joind.in/talk/228f1
@SammyK #pnwphp
7.x
Slide 89
Slide 89 text
joind.in/talk/228f1
@SammyK #pnwphp
7.x
Slide 90
Slide 90 text
joind.in/talk/228f1
@SammyK #pnwphp
7.x
Notice: Array to string conversion in /
foo.php on line 6
Notice: Undefined variable: Array in /
foo.php on line 6