30% of Laravel code is Symfony

Javier Eguiluz
3 min readDec 14, 2017

--

Laravel is a popular PHP framework used to develop monolithic web applications. Laravel is known for using lots of third-party libraries, mostly Symfony Components. I was curious about how much code each vendor provides to Laravel apps, so I gathered some stats.

Creating the project

I run the following command, as recommended by the Laravel docs, to create a new Laravel 5.5.22 app:

composer create-project --prefer-dist laravel/laravel my-project

And these are the default contents of the vendor/ directory in a new and unmodified Laravel app:

Default contents of vendor/ dir in a new Laravel app

Analyzing the vendor/ directory

I used the well-known cloc command line utility to count the lines of each vendor directory. This is for example the output of cloc for the vendor/laravel/ dir:

$ cloc vendor/laravel/907 text files.
901 unique files.
67 files ignored.
T=6.57 s (127.8 files/s, 17502.6 lines/s)
----------------------------------------------------------
Language files blank comment code
----------------------------------------------------------
PHP 801 14423 49490 49404
JSON 30 0 0 1286
CSS 1 47 11 229
Javascript 6 19 45 38
SASS 2 11 11 25
----------------------------------------------------------
SUM: 840 14500 49557 50982
----------------------------------------------------------

In this analysis, we’ll only focus on PHP code, so we’ll ignore non-PHP file types and the number of blank and comment lines. All in all, Laravel apps contain 49,404 lines of PHP code provided by Laravel itself. These are the results for the other main vendors:

Thanks to these stats, we can say that:

  • Laravel apps contain 373,345 lines of PHP code by default.
  • In Laravel apps, 13% of code comes from Laravel (49,404 lines) and 87% comes from third-party vendors (323,941 lines).
  • The biggest single vendor in Laravel apps is fzaninotto/, which provides the Faker library used to generate realistic fake data in tests.
  • In Laravel apps, more than 29% of code comes from Symfony (108,407 lines of code = 81,688 from symfony/ and 26,719 from swiftmailer/, which is the official Symfony mailer).

Conclusion

These stats show why PHP keeps winning after all these years. While other communities struggle with the NIH (Not Invented Here) syndrome and dedicate their resources to reinvent the wheel, PHP increasingly follows the PFE (Proudly Found Elsewhere) philosophy. Composer and high quality Open Source projects are the main drivers of this phenomenon, so don’t forget to thank them for their work!

This collaboration between competing projects (e.g. Laravel and Symfony) brings lots of benefits to developers, including more gentle learning curves and richer and more connected ecosystems. Besides, battle-testing the same libraries in lots different projects is great to make them ready for all kinds of business applications. That’s why Symfony Components are used by most PHP projects and have more than 1 billion downloads.

--

--