 [ ← blog / drupal ](/) Nov 07, 2023  ·  \#drupal  ·  2 min read 

# PHPStan is now running for all Drupal modules on GitLab CI!



The [Drupal Association](https://www.drupal.org/association) has been working on a monumental effort to migrate away from our bespoke [DrupalCI](https://www.drupal.org/project/drupalci_testbot) continuous integration system to GitLab CI as part of the [GitLab Acceleration Initiative](https://www.drupal.org/drupalorg/roadmap/gitlab-acceleration). Drupal core's test runs are [*five times faster* using GitLab CI](https://www.drupal.org/about/core/blog/drupal-cores-gitlab-ci-testing-is-now-five-times-faster-than-drupalci). I have loosely followed the progress as Drupal moves from our custom-built infrastructure onto GitLab. But someone shared with me a little feature I missed: adding a [PHPStan job to the default GitLab CI templates](https://www.drupal.org/project/gitlab_templates/issues/3395419)!

Fran Garcia-Linares ([fjgarlin](https://www.drupal.org/u/fjgarlin)) is the engineer from the Drupal Association who has been working on the GitLab CI templates. [GitLab supports templates](https://docs.gitlab.com/ee/administration/settings/instance_template_repository.html) to allow reusing configuration for continuous integration workflows. The new [`phpstan`](https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.main.yml#L251-292) job does a handful of things, and I love its approach.

- Allows modules to commit a `phpstan.neon` file to provide customized PHPStan configuration, such as `level: 9` or specific errors to be ignored.
- Exports errors as a JUnit report, GitLab quality report for the user interface, and terminal output for users to manually review.
- Generates [a baseline file](https://phpstan.org/user-guide/baseline) uploaded as an artifact that can be included with the project so they can start using PHPStan and accept all existing errors to be fixed later on!

What I found very creative was the way each report has been generated. PHPStan uses a [result cache](https://phpstan.org/user-guide/result-cache) to make subsequent scans faster. The `phpstan` job uses this to create multiple reports from the results. It runs PHPStan three times with different outputs, capturing the exit code after each job run and generating the baseline.

With most of my open source work being on [phpstan-drupal](https://github.com/mglaman/phpstan-drupal) or [Retrofit](https://github.com/retrofit-drupal/retrofit), I haven't worked on Drupal modules that often recently. I haven't had a chance to try out GitLab CI on Drupal.org yet. I need to set aside some time to check it out!

Is your module using GitLab CI yet? If not, check out the extensive documentation: <https://www.drupal.org/node/3356364/>

 

  ![](/themes/custom/mglaman/images/headshot.webp)Thanks for reading

I write about Drupal, PHP, and the quiet infrastructure behind large sites — caching, config, and testing. New posts land every week or two.

 [Subscribe via RSS →](/rss.xml) [About me →](/about-me) 

 



 

  [← Older

To POST, or PUT, PATCH, and DELETE? URLs are cheap, but API design matters

 ](/blog/post-or-put-patch-and-delete-urls-are-cheap-api-design-matters) [Newer →

A playground to test Drupal code with phpstan-drupal is coming soon!

 ](/blog/playground-test-drupal-code-phpstan-drupal-coming-soon)