Continue reading to learn more about the PHPStan code analysis we have been using since 2017!
Since the earliest releases of PHPStan, I have been a strong advocate of introducing such a tool for static analysis to our PHP projects.
That dates back to 2017 when we were already running PHPStan v0.9 for our largest Symfony project. Being version 0.9 meant that the tool was still in its early development stages and not marked as stable. Even this early version provided valuable help in writing more robust code for our clients, as we learnt how to solve the tool's edge cases.
Last November 11th PHPStan released the long-awaited v2.0. It includes a lot of new features and improvements, they also offer PHPStan ElePHPants (spoiler: we at Liip ZH registered as a distributor of the PHPStan orders, read on!)
A few of the many improvements included:
- Introduction of the Level=10 (more strict on mixed types)
- New
list<T> type
- Reduced memory consumption (and cache storage)
- Validate inline PHPDoc
@var
tag type - Smooth upgrade: PHPStan v1.12 + strict-rules + bleeding-edge flags behave as PHPStan v2.0
For more technical details, refer to Ondřej Mirtes's blog post on the PHPStan 2.0 release.
Test-case: performance gains
For one of the test projects, we wanted to test the performance improvements advertised by PHPStan v2.0.
The project is a legacy Symfony project consisting of 3100 PHP files and around 288k lines of code (not including comments or blank lines). PHPStan is configured with its doctrine, Symfony and PHPUnit extensions, which help to further improve the static analysis on that project.
Here are some preliminary test runs of PHPStan v1.12 Vs running with the pre-v2.0 features enabled.
Tests setup: the PHPStan cache folder has been removed before each run; memory usage and timing reported here are the best of 3 runs.
v1.12 | pre-v2.0 | difference | |
---|---|---|---|
Execution time | 9m 56s | 4m 3s | - 5m 50s (-60%) |
Memory usage | 3.1 GB | 1.54 GB | - 1.47 GB (-50%) |
The improvements are impressive for our project.
Such numbers will improve the performances of our CI/CD pipelines, and the overall developer experience when working on new changes.
LIIP as ElePHPant distributors
We benefited greatly from introducing PHPStan in our development pipeline from the early days, so we wanted to show our support for the project and the great work done by Ondřej.
We (Emanuele and David) signed up to act as distributors of PHPStan ElePHPants and merch.
By using our link to place your order you will get the following:
- Free shipping;
- Pickup at the Symfony ZH user group event (or at any Liip office);
Use the following link: https://phpstan.org/merch?distributor=symfony-zurich
Note that Liip is not affiliated with PHPStan, nor do we get any monetary revenue from the orders: we support it because it is a great Open-Source project!
Place your orders before Sunday, December 8th.
The expected delivery is around May-June 2025.