Problem/Motivation

At #3417410: Set up to date the gitlab-ci.yml configuration We found we are not passing the validation checks for PHPStan.

An initial list of errors can be found at : https://git.drupalcode.org/issue/examples-3417410/-/jobs/699833

We would like to have the module Examples passing these checks with the final goal of having a clean pipeline to be used as base for the incoming examples or maintenance tasks of this module.

Proposed resolution

  1. Follow the instructions from https://www.drupal.org/docs/develop/development-tools/phpstan/getting-st... to have running PHPStan locally.
  2. Run the PHPStan against the Examples module.
  3. Fix all findings and make a MR with the fixes.

Notes: We don't have any phpstan.neon defined for this project, we might need to have one to adjust / ignore certain well known issues like Drupal Core does.
In addtion, ideally we are aiming for Level 8, but decide if it is really doable.

CommentFileSizeAuthor
#3 initial-report.txt21.73 KBjlbellido

Issue fork examples-3417527

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

jlbellido created an issue. See original summary.

jlbellido’s picture

jlbellido’s picture

StatusFileSize
new21.73 KB

I'm attaching the initial report with all the issues detected before fixing anything:

jlbellido’s picture

Hello,

I've created an initial MR fixing most of the errors reported. It still pending the following one:

 ------ --------------------------------------------------------------------- 
  Line   modules/file_example/src/FileExampleSubmitHandlerHelper.php          
 ------ --------------------------------------------------------------------- 
  460    Class Drupal\devel\DevelDumperInterface not found.                   
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  

I don't really know if by using Stub files we can fix it since it is a conditional class not always present (depending is Devel is required or not).

jlbellido’s picture

Status: Active » Needs review

I've checked in deep the error from #5 but I think Stub files is not the right way because they are meant for other kind of scenarios according to (https://phpstan.org/user-guide/stub-files). Therefore I don't see other way to get rid of it than ignoring it via php-baseline.neon

I've added a new commit with this approach.

Now we are passing the PHPStan checks for Level 1:

$ php ../vendor/bin/phpstan analyze --configuration modules/contrib/examples/phpstan.neon modules/contrib/examples
 242/242 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
                                                                                                                        
 [OK] No errors                                                                                                      

I think this is now ready to be reviewed.

jlbellido’s picture

After #3417410: Set up to date the gitlab-ci.yml configuration has been merged, now we can see we are passing the PHPStan check within !32 if we compare it with the last run on the main project (https://git.drupalcode.org/project/examples/-/pipelines/85372)

Therefore I'd say this is fully ready to be reviewed by someone else.

Thanks!

avpaderno’s picture

Status: Needs review » Needs work

avpaderno’s picture

Status: Needs work » Needs review

apaderno changed the visibility of the branch 3417527-fix-phpstan-detected to hidden.

  • apaderno committed 4b79aeaf on 4.0.x
    Issue #3417527: Fix PHPStan detected errors
    
avpaderno’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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