Fix PHPStan for previous major

Created on 11 September 2025, 9 days ago

Problem/Motivation

PHPStan was fairly recently added to GitlabCI for Previous Major. As this is running against D10, it doesn't recognize D11 attributes, so PHPStan reports the following errors:

 ------ ----------------------------------------------------------------- 
  Line   src/Hook/TokensHooks.php                                         
 ------ ----------------------------------------------------------------- 
  18     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
  45     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
 ------ ----------------------------------------------------------------- 
 ------ ----------------------------------------------------------------- 
  Line   src/Hook/VerifyEmailHooks.php                                    
 ------ ----------------------------------------------------------------- 
  19     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
  30     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
 ------ ----------------------------------------------------------------- 
 ------ -------------------------------------------------------------------- 
  Line   tests/src/Functional/VerifyEmailRoutingTest.php                     
 ------ -------------------------------------------------------------------- 
  18     Attribute class PHPUnit\Framework\Attributes\Group does not exist.  
 ------ -------------------------------------------------------------------- 
 ------ -------------------------------------------------------------------- 
  Line   tests/src/Functional/VerifyEmailSetupTest.php                       
 ------ -------------------------------------------------------------------- 
  13     Attribute class PHPUnit\Framework\Attributes\Group does not exist.  
 ------ -------------------------------------------------------------------- 
 ------ ----------------------------------------------------------------------- 
  Line   verify_email.module                                                    
 ------ ----------------------------------------------------------------------- 
  17     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
  25     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
  33     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
  41     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
 ------ ----------------------------------------------------------------------- 
 [ERROR] Found 10 errors

Add a "before script" to GitlabCI to remove the Hook attributes before PHPStan runs for previous major.

Steps to reproduce

See pipeline: https://git.drupalcode.org/issue/verify_email-3545565/-/jobs/6506464

Proposed resolution

Add a "before script" to .gitlab-ci.yml to remove the Hook attributes before PHPStan runs for previous major. This will mean that when PHPStan runs for previous major, the attributes will not be present. However, as the script only gets run for that specific instance, everything else will be properly checked.

Remaining tasks

  1. Add a new section to .gitlab-ci.yml: phpstan (previous major):
  2. Add a before script under it: before_script:
  3. Add line to the before script for each hook to be removed, specifying the path to he folder it should be removed from. For example, the LegacyHook attribute command would look something like this: - sed -i '/#\[LegacyHook\]/d' $DRUPAL_PROJECT_FOLDER/*.module
  4. Repeat for #[Hook] and #[Group] attributes, but update the paths to the test directories.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

📌 Task
Status

Active

Version

1.1

Component

Code

Created by

🇮🇪Ireland lostcarpark

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !37Fix PHPStan for previous major. → (Merged) created by nidhi27
  • Pipeline finished with Success
    6 days ago
    Total: 171s
    #599069
  • Pipeline finished with Success
    6 days ago
    Total: 324s
    #599103
  • Pipeline finished with Success
    6 days ago
    Total: 296s
    #599126
Production build 0.71.5 2024