22 \ August 2019 \ http://www.phparch.com
Can You Migrate Any Legacy Code Under One Month?
- It might take months and bring
zero value to the business.
If I owned the business, all I would
hear, “We want to play, give us your
money for an uncertain amount of
time, and you’ll get nothing of value in
return.”
That’s the problem, as programmers,
we only get money for the time spent
at work. When we go home at the end
of the day, we don’t care if the business
lasts through the next summer.
We care about ourselves. We pay rent
and expect to live for the next year with
the same quality, we pay for Spotify
and expect it to give us enjoyable songs
for the long term. The business owner
is like us—they pay us monthly and
expect long term sustainability.
We need to learn to make a business
case for the value of migrating to a new
framework or language version.
How to be One with the Busi-
ness?
Rector is not a tool to play and
migrate code just because it can. It
needs to bring value to the business.
That’s why we need a mind shift from
“must-have” to “it’s better”:
- When we migrate from Zend 1 to
Symfony 4 in 30 days, we’ll lose a
month of work of two people, but
the delivery time for our tasks will
drop from four hours to 30 minutes.
In three months, we have it paid for,
and then we profit. - Upgrading from PHP 5.6 to PHP
7.3 allows us to run 50% fewer
servers and to scale better at traffic
peaks." - "When we use Symfony, it stream-
lines hiring new developers. Last
month we had a meeting with one
Zend developer, but six Symfony
developers. (True story.) - The Symfony community is much
more active than Zend in our coun-
try, by the numbers it’s 12 meetups
a year to zero meetups. It’s easier to
7 NEON: https://ne-on.org/
8 YAML: https://yaml.org/
learn and to share our know-how
there, which eventually brings us
more developers, with a better team
and code quality, therefore, cheaper
feature delivery.
With this in mind, we started the
migration from Nette to Symfony.
Instant Migration with Rector
What were the patterns we needed to
migrate? Output 1 and Output 2 shows
a diff of some migrations. We had
to update the following libraries and
patterns.
- NEON^7 to YAML^8 for the configu-
ration system.
Output 1
- <?php declare (strict_types = 1);
- -namespace App\Presenter;
- +namespace App\Controller;
- -use Nette\Application\AI\Presenter;
- +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- -use Nette\Http\Request;
- +use Symfony\Component\HttpFoundation\Request;
- -final class SomePresenter extends Presenter
- +final class SomeController extends AbstractController
- {
- public static function someAction()
- public static function someAction(Request $request)
- {
- $header = $this->httpRequest->getHeader('x');
- $header = $request->headers->get('x');
- $method = Request::POST;
- $method = Request::METHOD_POST
- }
- }
Output 2
- <?php
- namespace App;
- use Entrydo\RestRouteList;
- use Entrydo\Restart;
- final class RouterFactory
- {
- private const PAYMENT_RESPONSE_ROUTE = '/payment/process';
- // 150 more!
- public function create()
- {
- $router = new RestRouteList();
- $router[] = RestRoute::get(self::PAYMENT_RESPONSE_ROUTE,
ProcessGPWebPayResponsePresenter::class);
- $router[] = RestRoute::get(self::PAYMENT_RESPONSE_ROUTE,
- // 150 more!
- return $router;
- }
- }