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:
https://git.drupalcode.org/project/block_class/-/blob/3.1.x/phpstan.neon...

We would like to enforce a stricter 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/block_class/ -l 10

Many errors will be displayed.

Proposed resolution

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

Additional change: Extend phpcs quality coverage with the DrupalPractice ruleset.

Similar issues

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 22aa5d6d on 3.1.x
    Issue #3629522 by dydave: PHPSTAN: Raised validation level from 0 (min)...
dydave’s picture

Status: Active » Fixed

Quick follow-up on this issue:

The goal of this MR and issue in general is to try to increase as much as possible code quality control coverage to provide a stricter and tighter frame for code generation with AI.
The purpose of raising the validation level of the phpstan job to 10 is to enforce a certain standard of code quality production.

Most of the work in the MR was assisted with AI which made code changes and fixed errors iteratively, with approval, until all errors were fixed.
Then I had a few iterations as well to fix the Gitlab CI configuration for the mglaman/phpstan-drupal extra rules.

Job PHPStan Config Level
Current 2.3.1 phpstan.neon plus phpstan-strict.neon max (10)
Next minor 2.3.1 phpstan.neon plus phpstan-strict.neon max (10)
Next major 2.3.1 phpstan.neon plus phpstan-strict.neon max (10)
Previous major 1.12.34 phpstan.neon only max (9)

 

Added also PHPCS config file to explicitly require the 'DrupalPractice' ruleset, which adds 40 extra sniffs.

After doing some tests locally and since all the jobs were passing 🟢, I went ahead and merged the changes above at #3. 🥳

Basically, the idea behind all this is to increase as much as possible the quality controls though the Gitlab CI quality gates in order to be as "safe" as possible maintaining the code base with AI.

At this point, we have greatly increased the checks for PHPCS and PHPSTAN, plus, we also have Gitlab Advanced Security, Semgrep and Secret Detection...

We could probably consider this is a pretty good example or template of module's pipelines configuration, that could maybe be reused for other modules.

Since all the work to be carried in this issue should have been completed at this point, marking as Fixed, for now.
Thanks in advance!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.