Problem/Motivation

Currently, the module uses the default Gitlab CI templates for the PHPSTAN job:
https://git.drupalcode.org/project/gitlab_templates/-/raw/default-ref/as...

With the lowest rule level: 0, which only does very basic PHP code validation.

We would like to enforce stricter a validation of the module's code base, see the PHPSTAN rules levels:
https://phpstan.org/user-guide/rule-levels

Steps to reproduce

Run locally:

./vendor/bin/phpstan analyze web/modules/contrib/admin_toolbar/ -l 6

Many errors will be displayed.

Proposed resolution

Fix all validation errors and add a phpstan.neon configuration file to set the rule level to 6 for the job on Gitlab CI.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dydave created an issue. See original summary.

  • dydave committed c4ac4d9a on 3.x
    Issue #3517506 by dydave: PHPSTAN: Raised validation level from 0 (min)...
dydave’s picture

Status: Active » Fixed

Quick follow-up on this issue:

Starting from level 3, I gradually raised the level and each time fixed all the errors prompted by PHPSTAN, until reaching level 6.

Fixed all validation errors, mostly:

  • Updated Doc comment blocks return types.
  • Updated Doc comment blocks param types.
  • Added inline @var types definitions.
  • Changed 4 lines of code, to add elvis operators and reorder chained calls.
  • Caught a wrong variable passed in assert function in a Test class.

 
Added project's phpstan.neon file to raise validation level to 6 and ignore certain error messages.
 

Very few lines of code with very minor changes were impacted in the merge request.

Since the Tests of the MR all passed 🟢, I went ahead and merged the changes above at #3.

The configuration change was made on Gitlab CI by adding the file: phpstan.neon, forcing rule level to 6.

This should be helpful keeping module's code properly maintained with the evolution of the different Core versions, APIs and PHP versions.

PHPSTAN validation is currently not required to merge.

Marking issue as Fixed for now.

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.