phparchitect-2019-08

(Rick Simeone) #1

20 \ August 2019 \ http://www.phparch.com


FEATURE


Can You Migrate Any Legacy Code Under One Month?


Tomas Votruba


According to PHP Framework Trends1 from Packagist, there were over 1,258 million
downloads of open-source PHP frameworks in the last 12 months. That’s a huge number!
But how many of them are on the latest version? How many of them are stuck on version 0
or 1, that’s not even on Packagist? Also, how many of you have a custom PHP framework that
you hate? What if I tell you there is a way you all could use the latest version of your favorite
framework and PHP 7.4 by the end of 2019?

1 PHP Framework Trends:
https://phpa.me/votruba-framework-trends
2 PSR-4 autodiscovery: https://phpa.me/votruba-autodiscovery
3 Entry.do: https://entry.do
4 phploc: https://github.com/sebastianbergmann/phploc


Every PHP Framework Is Dying
It all begins in a small country in the center of Europe—the
Czech Republic. You might have heard about us thanks to
Nette, PHPStan, or some Doctrine and Symfony contributors.
Nette is a PHP framework that was released in 2008 and is
used mostly by Czech companies. If you’ve never heard about
it, the very raw description would be “close to Symfony in
features and Laravel in simplicity.”
Now, the problem with Nette, just like any software is that
it ages fast. Do you remember the release of PHP 5.3 in June
2009? This “namespace” thing, what a cool feature, I loved it.
Now it’s 2019, and this is the status quo. This cycle is a natural
process of life, or would you prefer PHP 5.3 to be the last PHP
version ever?

“Once you stop learning, you start dying.”
–Albert Einstein

PHP frameworks, like any software, get old. There is always
a better version of it somewhere, or another framework that
follows more modern standards, has a clearer API or trendy
features, and is easier to learn.

“The only thing that is constant is change.”
–Heraclitus

For this article and showing our migration path, I’ll use
Nette because that’s the first project we migrated in under a
certain time. I’ll tell you later the exact number of days! Keep
reading.
Also, I’ll use Symfony as a go-to project, because that’s our
personal preference. You can replace it with your favorite
framework.

Why do we like Symfony? It has amazing PSR-4 autodis-
covery^2 that makes your config five lines long. Its six-month
release cycle gets me excited all the time, and it has a great
community that sometimes feels like my own family.

What Did We Do?
Now that we know all software is dying, and the natural
process of the software life-cycle, let’s get technical!
We migrated Entry.do^3 —an API application built on
controllers, routing, and Kdyby integrations of Symfony and
Doctrine. The application has been running in production for
the last four years. We migrated it from Nette 2.4 to Symfony
4.2.

How Big is the Project?
Honestly, with pattern refactoring the size doesn’t matter,
but people still tend to care about it. Quantitative numbers
can be used to derive qualitative statements since, for
example, size and complexity can behave orthogonal to each
other. Something small can be very complicated, and some-
thing big does not have to be complex at all.
If we don’t count tests, migration, fixtures, etc., the applica-
tion has 270 PHP files totaling 54,357 lines without comments.
These metrics were calculated using phploc^4.
To give you an idea, Laravel 5.8 has 72,519 lines (without
comments) at the time of writing.

Figure 1. Entrydo website
Free download pdf