http://www.phparch.com \ August 2019 \ 23
Can You Migrate Any Legacy Code Under One Month?
- Latte^9 to Tw i gas the templating
engine. - Presenter to Controller—C part
of Model-View-Controller (MVC)
pattern.
You can move routes from single
RouteFactory class to @Route annotation
per Controller __invoke() action as in
Output 3.
You can change a few new
How Long Did It Take?
On January 27th, 2019, we met above
Nette application and, on February 13th,
2019, the Symfony application went to
the staging server. On February 14th,
we celebrated a new production appli-
cation in addition to Valentine’s Day.
We completed it in less than 17 days.
Done, finished, deployed, goodbye.
You’re counting the estimate, 17 * 40
- 2—stop, I’ll count it for you: 2 * 40
hours = 80 hours.
It took roughly 50 hours to prepare
the pattern set and 10 hours to debug
one event race-condition. Now the
migration of a similar project would
take us 15-20 hours.
How Can You Do It?
There is zero chance you have a Nette
project you want to migrate to Symfony, but just in case, the
migration set in Rector is ready. Just use it](https://phpa.me/
rector-nette-symfony):
composer require rector/rector --dev # install
vendor/bin/rector process src --set nette-to-symfony -n # dry run
vendor/bin/rector process src --set nette-to-symfony
It’s not perfect since you’ll have to cover edge cases that are
specific to your code, but it can save you 80% of the tedious
work that is typical for this migration.
To be Continued
In the next article, I’ll teach you about pattern refactoring
with Rector and how you can use it to migrate any PHP code
you have now to your dream code.
9 Latte: https://latte.nette.org/en/
Tomas Votruba is a regular speaker at
meetups and conferences and writes regu-
larly at http://www.tomasvotruba.cz. He
created the Rector project and founded the
PHP community in the Czech Republic in
- He loves meeting people from the PHP
family so he created https://friendsofphp.org
which is updated daily with meetups all over
the world. @votrubaT
Output 3
- namespace App Presenter;
- +use Symfony\Component\Routing\Annotation\Route;
- final class ProcessGPWebPayResponsePresenter
- {
- /**
- @Route(path = "/payments/gpwebpay/process-response", methods="GET"})
- */
- public function __invoke()
- {
- // ...
- }
- }
Output 4
- <?php
- class SomePresenter
- {
- /**
- @var ResponseFactory
- */
- private $responseFactory;
- public function __construct(ResponseFactory $responseFactory)
- {
- $this->responseFactory = $responseFactory;
- }
- public function someAction()
- {
- return new OKResponse($response);
- return $this->responseFactory->createJsonResponse($response);
- }
- }
Related Reading
- Writing Better Code with Four Patterns
by Joseph Maxwell, January 2017.
http://phparch.com/magazine/2017-2/january - Department of Breaking Changes: Launching PHP 7 in
a Highly Available Web World
by Grant Dickie, May 2019.
https://phpa.me/npr-migrate-php7 - The Dev Lead Trenches: How Long Will It Take?
by Chris Tankersley, September 2018.
https://phpa.me/dev-lead-sept-2018