Fix PHPStan for previous major

Created on 6 September 2025, 15 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   smart_trim.module                                                      
 ------ ----------------------------------------------------------------------- 
  16     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
  43     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
  51     Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.  
 ------ ----------------------------------------------------------------------- 
 ------ ----------------------------------------------------------------- 
  Line   src/Hook/SmartTrimHooks.php                                      
 ------ ----------------------------------------------------------------- 
  16     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
  30     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
  52     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.  
 ------ ----------------------------------------------------------------- 
 ------ -------------------------------------------------------------------- 
  Line   tests/src/Kernel/TokenTest.php                                      
 ------ -------------------------------------------------------------------- 
  25     Attribute class PHPUnit\Framework\Attributes\Group does not exist.  
 ------ -------------------------------------------------------------------- 
 [ERROR] Found 7 errors  

Steps to reproduce

See pipeline: https://git.drupalcode.org/project/smart_trim/-/jobs/6439605

Proposed resolution

Add an instruction to tell PHPStan to ignore the attribute lines: @phpstan-ignore-next-line

Remaining tasks

Fix it.

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

2.0

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

  • Issue created by @lostcarpark
  • Merge request !116Add @phpstan-ignore-next-line for attributes. → (Merged) created by lostcarpark
  • Pipeline finished with Failed
    15 days ago
    Total: 402s
    #591789
  • Pipeline finished with Running
    15 days ago
    #591800
  • Pipeline finished with Failed
    15 days ago
    Total: 229s
    #591803
  • Pipeline finished with Failed
    15 days ago
    Total: 298s
    #591815
  • Pipeline finished with Failed
    15 days ago
    Total: 221s
    #591826
  • Pipeline finished with Failed
    15 days ago
    Total: 267s
    #591835
  • Pipeline finished with Success
    15 days ago
    Total: 217s
    #591839
  • 🇮🇪Ireland lostcarpark

    I tried adding @phpstan-ignore-next-line lines, which worked for me in another module, but these were giving "no error to ignore" errors when testing against current versions.

    I'm not very happy with the approach of adding ignore statements, since they could prevent genuine issues from being missed.

    So I thought it would be good if it could be added for the previous major, which is the only time it's needed. Adding a before_script to insert the ignore lines.

    However, after getting the tests to pass, I realised that deleting the attribute lines would achieve the same thing, but makes the script commands much simpler. So the updated .gitlab-ci.yml file includes a before script that runs for "phpstan (previous major)" only, that deletes the attribute lines.

    I hoped to make this issue only about the attributes, but phpstan (next major) is required to pass, so I copied mike's change from Allow the possibility to specify which tags to be stripped when Strip HTML checkbox is ticked. Needs work to fix the deprecation issue.

  • Pipeline finished with Success
    9 days ago
    Total: 227s
    #597357
  • Pipeline finished with Failed
    9 days ago
    Total: 194s
    #597360
  • Pipeline finished with Canceled
    9 days ago
    Total: 131s
    #597369
  • Pipeline finished with Success
    9 days ago
    Total: 184s
    #597374
  • Pipeline finished with Success
    9 days ago
    Total: 328s
    #597395
Production build 0.71.5 2024