Skip to main content

phpstan-drupal now supports PHPStan 2.0

Published on

PHPStan 2.0 was released a month ago, a massive milestone for the project. To learn about all the changes, I recommend reading the release announcement. phpstan-drupal now has a PHPStan 2.0 compatible release: https://github.com/mglaman/phpstan-drupal/releases/tag/2.0.0. The 1.x branch will be maintained as long as a version of Drupal Core uses it, at least until Drupal 10's end-of-life near the end of 2026. If applicable, I will backport bug fixes and features to 1.x.

What's new in phpstan-drupal 2.0.0?

At the moment, nothing much. Support for Drupal 9 has been removed, removing 1,000+ lines of code and making phpstan-drupal much easier to maintain. Agan thanks to Spokje.

Does Drupal core use PHPStan 2.0?

Not yet! Drupal Core still uses PHPStan 1.0. Getting a compatible release of phpstan-drupal was a blocker. I owe so many thanks to Spokje, who performed the phpstan-drupal upgrade to PHPStan 2.0. I wouldn't say it was hard work; it was just a lot of tedious work.

You can follow this issue for the upgrade of Drupal Core to PHPStan 2.0: https://www.drupal.org/project/drupal/issues/3486713. If it is updated before 11.2.0, then phpstan-drupal 1.x will be supported until 11.1.x loses security coverage, unless that comes before 10.x's end-of-life.

Can we move more of phpstan-drupal into Drupal Core?

Yes! We can. However, part of that will involve making features of phpstan-drupal toggleable. See https://github.com/mglaman/phpstan-drupal/issues/810 as an example. If we can turn off some of the dynamic return type extensions, we can improve the in-code PHPDocs to replace them.