Skip to main content

🥳 phpstan-drupal 0.12.10 out!

Published on

I just released phpstan-drupal 0.12.10, which includes a major bug fix and major feature.

Thank you, sponsors.

Before diving into the changes, I would like to thank my GitHub Sponsors and contributors on Open Collective who help fund my open source development time for projects like phpstan-drupal. Especially a big thanks to undpaul and intracto for being organization-level sponsors of my work.

Through my GitHub Sponsors and Open Collective, I'm able to cover roughly three hours of development a month.

What's new?

Better compatibility when drupal/core-dev is not installed

Turns out a rule in phpstan-drupal was causing analysis to crash if PHPUnit was not installed. This was due to an interface check via reflection. If the interface could not be autoloaded the script would crash. 😱. So a little change was made:

// Before
$classReflection->implementsInterface($item)

// After
$implemented_interfaces = $classReflection->getInterfaceNames();
foreach ($allowed_list as $item) {
  if (in_array($item, $implemented_interfaces, true)) {

The interface doesn't need to be available for autoloading this way.

I have added a new GitHub Actions workflow for testing without the drupal/core-dev package, which installs PHPUnit and other testing dependencies.

Dynamic loading of included files from module_load_include

This is a big deal! It's not as common in Drupal 8 or 9 as in Drupal 7, but often times modules would provide extra include files like mymodule.extra.inc.  Most of these were switched to the loadIncludes method of the module handler, but the module_load_include function still persists. The main difference is that module_load_includes allows loading files from uninstalled modules. The main point is this: PHPStan had no idea how to load functions from those files, so any call to those functions were reported as undefined function calls.

Now, this is fixed! When it comes to Drupal core, the main problem would have occurred when analyzing the locale.module file.

I have added that as test coverage.

Helping continue development

I would love to continue building on phpstan-drupal. I would really like to start adding rules which help folks write better code. If you'd like to see a more expansive phpstan-drupal project, considering funding my time via GitHub Sponsors or the project's Open Collective.

Alternatively, I am also considering making a private package called phpstan-drupal-rules that would be available via a license. This package would help fund maintenance and allow me to codify my Drupal code review knowledge into rules that could be added to your projects. I would love to hear your thoughts on this idea.

I'm available for one-on-one consulting calls – click here to book a meeting with me 🗓️