phparchitect-2019-08

(Rick Simeone) #1
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


  1. <?php declare (strict_types = 1);



  2. -namespace App\Presenter;

  3. +namespace App\Controller;



  4. -use Nette\Application\AI\Presenter;

  5. +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

  6. -use Nette\Http\Request;

  7. +use Symfony\Component\HttpFoundation\Request;



  8. -final class SomePresenter extends Presenter

  9. +final class SomeController extends AbstractController

  10. {



    • public static function someAction()





    • public static function someAction(Request $request)



  11. {



    • $header = $this->httpRequest->getHeader('x');





    • $header = $request->headers->get('x');







    • $method = Request::POST;





    • $method = Request::METHOD_POST



  12. }

  13. }


Output 2


  1. <?php



  2. namespace App;



  3. use Entrydo\RestRouteList;

  4. use Entrydo\Restart;



  5. final class RouterFactory

  6. {



    • private const PAYMENT_RESPONSE_ROUTE = '/payment/process';



  7. // 150 more!



  8. public function create()

  9. {

  10. $router = new RestRouteList();



    • $router[] = RestRoute::get(self::PAYMENT_RESPONSE_ROUTE,
      ProcessGPWebPayResponsePresenter::class);



  11. // 150 more!



  12. return $router;

  13. }

  14. }

Free download pdf