Zbav se legacy kódu s Rectorem jednou pro vždy

 Tomas Votruba.cz

 

getRector.org

2019-12-11

 

Hi, I'm Tomas!

  • freelance consultant
  • legacy migrator
  • speaker
  • blogger
  • open-source addict
  • "It's not possible"
  • 8-14, 5-min break/hour
  • 1) About Legacy Migration (theory)
  • 2) How & why do it (theory + discussion)
  • 3) Hands on legacy coding (coding :))

*2015-11

PHP 7.0 - 809 lines

PHP 7.3 - 651 lines

Symfony 4.0 - 1145 lines

260 results

Text

Text

Code becomes legacy

as soon as it's been written

Text

Text

Code becomes legacy

as soon as it's been written

Text

Knowledge

learned

Time to Refactor Legacy

54 357 lines

151 REST routes

vendor/bin/rector process src

--set nette-to-symfony

Time to Refactor Legacy

4

1

4

1

4

2

Any legacy project

can be migrated to

a new framework

in 1 month.

How to do it... Right and Fast?

  • set time limit - 1 month? 2 months?
  • separate from feature team - keep developing
  • know what is the final goal
  • split it to 5-10 smaller milestones
  • the development is very slow at start - be ready for that
  • what are the edge cases?
  • what is automated, what manuall?
  • what exactly is the priority? vs. "migrate everything"

Time to Refactor Legacy

  • "We already switched from Nette to Symfony, we don't need Rector."
  • "We already switched from Nette to Symfony, we don't need Rector."
  • "No problem. How long did it take?"
  • "We already switched from Nette to Symfony, we don't need Rector."
  • "No problem. How long did it take?"
  • "Well, around 15 months in 5 people."
  • "We already switched from Nette to Symfony, we don't need Rector."
  • "No problem. How long did it take?"
  • "Well, around 15 months in 5 people."
  • "We already switched from Nette to Symfony, we don't need Rector."
  • "No problem. How long did it take?"
  • "Well, around 15 months in 5 people."
  • you have to have CI with
    • coding standards, PHPStan
    • tests
  • ​the better code ecosystem → the better & faster work is
  • if CEO wants it but CTO no, it fails
  • if CTO wants it but CEO no, it fails
  • if devs wants it but CTO no, it fails
  • if CEO wants it but CTO no, it fails
  • if CTO wants it but CEO no, it fails
  • if devs wants it but CTO no, it fails
  • if devs, CTO and CEO wants it, it's a matter of time (e.g. Spaceflow, Entrydo)
  • Coolnes Factor?
  • Beause I/he/she/they said it?
  • Because your boss told you?
  • Because YOU want?
  • Coolness Factor?
  • Beause I/he/she/they said it?
  • Because your boss told you?
  • Because YOU want?
  • This is often more important than technical code itself
  • 80 % is planning
  • Take the first 50 % with patience
  • Have a whole team team on board
  • Have a safety net
  • Why do you want to migrate?

How to Avoid

Legacy in the Future?

  • lets say it's 2020
  • migrate to the newest PHP 7.4
  • migrate to the newest your-favorite-framework, e.g. Symfony 5
  • migrate to the most modern patterns - Dependency Injection, PSR-4, PSR-12
  • add custom PHPStan rules to avoid past mistakes
  • add Rector to CI with new PHP/framework sets
  • never do this manually, or you'll end up the same shit again
  • when code-reviews start to be full of discussions and "maybes", automate it
  • when you don't know AST, learn it
  • dedicate time (to CEOs/CTOs) to make your project long-term, it will pay you back
  • in new                              (* 2016) we didn't add any feature for 6 months
  • we setup human-proof CI
  • we added coding-standard rules (now AST)
  • we removed all comments from code-reviews
  • if you make it right, you'll never see me again :)
  • it's all about setting up the process
  • CI holds the knowledge, not devs/CTO
  • this will increse juniors' work to senior level
  • migrate first
  • protect your code with CI
  • put custom PHPStan and Rector rules there
  • pay daily attention to legacy smells

More Technical?

Nikita Popov

Ondra Mirtes

Jan Tvrdik

Before: 850 files - 2628  missing @var props

After: 0 ✅

  • growing & active PHP community 
  • upgrade machine to PHP 8
  • vendor/bin/rector p src --set php80 ✅
  • migrate framework?                                      1 month week
  • active record → entity repository?          1 week day
  • upgrade-business companies
  • Rector CI - tireless & sleepless member of your team in your CI
     
  • faster + safer PHP-core development
  • BC break = 0 extra work
  • Add Easy Coding Standard
  • Add PHPStan
  • PSR-4 (RobotLoader, classmap, PHPUnit)
  • Normalize composer
  • Helpful composer scripts
  • Setup CI
  • Install Rector
  • Run Rector
  • Rector rule
  • Rector sets
  • First Rector rule
  • vendor/bin/rector create
  • PhpRector
  • FileSystemRector
  • when use which?
  • Follow @rectorPHP
  • Follow @votrubaT 

Thank you! Questions?

Zbav se legacy kódu s Rectorem jednou pro vždy (Clevero, 2019/12)

By Tomáš Votruba

Zbav se legacy kódu s Rectorem jednou pro vždy (Clevero, 2019/12)

  • 70
Loading comments...

More from Tomáš Votruba