Fix the issues reported by phpstan

Created on 23 October 2025, 20 days ago

Problem/Motivation

PHPStan throws the following errors when run on the module:

ddev phpstan web/modules/contrib/group_content_menu
Note: Using configuration file /var/www/html/phpstan.neon.
 107/107 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ ---------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/group_content_menu.module                                                                  
 ------ ---------------------------------------------------------------------------------------------------------------------- 
  120    Attribute class Drupal\Core\Hook\Attribute\LegacyModuleImplementsAlter does not exist.                                
  139    Attribute class Drupal\Core\Hook\Attribute\LegacyModuleImplementsAlter does not exist.                                
  197    Attribute class Drupal\Core\Hook\Attribute\LegacyHook does not exist.                                                 
  321    Parameter $job of function group_content_menu_tmgmt_source_suggestions() has invalid type Drupal\tmgmt\JobInterface.  
 ------ ---------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Controller/GroupContentMenuController.php                                                                                                                                 
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  89     Method Drupal\group_content_menu\Controller\GroupContentMenuController::handleOneMenuLimitation() should return bool|Symfony\Component\HttpFoundation\RedirectResponse but return statement is missing.  
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ -------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Controller/GroupContentMenuTranslationController.php               
 ------ -------------------------------------------------------------------------------------------------- 
  79     Call to deprecated method loadRevision() of interface Drupal\Core\Entity\EntityStorageInterface:  
         in drupal:10.1.0 and is removed from drupal:11.0.0. Use                                           
         \Drupal\Core\Entity\RevisionableStorageInterface::loadRevision instead.                           
 ------ -------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------ 
  Line   contrib/group_content_menu/src/Form/GroupContentMenuDeleteForm.php            
 ------ ------------------------------------------------------------------------------ 
  19     \Drupal calls should be avoided in classes, use dependency injection instead  
 ------ ------------------------------------------------------------------------------ 

 ------ ----------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Form/GroupContentMenuForm.php                                                           
 ------ ----------------------------------------------------------------------------------------------------------------------- 
  356    Method Drupal\group_content_menu\Form\GroupContentMenuForm::save() should return int but return statement is missing.  
 ------ ----------------------------------------------------------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Form/GroupContentMenuTypeForm.php                                                           
 ------ --------------------------------------------------------------------------------------------------------------------------- 
  84     Method Drupal\group_content_menu\Form\GroupContentMenuTypeForm::save() should return int but return statement is missing.  
 ------ --------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Form/MenuLinkItemDeleteForm.php                                                                                
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------- 
  15     Class Drupal\group_content_menu\Form\MenuLinkItemDeleteForm extends @internal class Drupal\menu_link_content\Form\MenuLinkContentDeleteForm.  
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------- 

 ------ ---------------------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Form/MenuLinkItemForm.php                                                                          
 ------ ---------------------------------------------------------------------------------------------------------------------------------- 
  15     Class Drupal\group_content_menu\Form\MenuLinkItemForm extends @internal class Drupal\menu_link_content\Form\MenuLinkContentForm.  
  26     Method Drupal\group_content_menu\Form\MenuLinkItemForm::save() should return int but return statement is missing.                 
 ------ ---------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------ 
  Line   contrib/group_content_menu/src/GroupContentMenuListBuilder.php                
 ------ ------------------------------------------------------------------------------ 
  67     \Drupal calls should be avoided in classes, use dependency injection instead  
  91     \Drupal calls should be avoided in classes, use dependency injection instead  
  101    \Drupal calls should be avoided in classes, use dependency injection instead  
  104    \Drupal calls should be avoided in classes, use dependency injection instead  
 ------ ------------------------------------------------------------------------------ 

 ------ --------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Hook/GroupContentMenuHooks.php        
 ------ --------------------------------------------------------------------- 
  30     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.      
  30     Instantiated class Drupal\Core\Hook\Order\OrderAfter not found.      
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
 ------ --------------------------------------------------------------------- 

 ------ --------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/Hook/NodeFormAlter.php                
 ------ --------------------------------------------------------------------- 
  44     Attribute class Drupal\Core\Hook\Attribute\Hook does not exist.      
  44     Instantiated class Drupal\Core\Hook\Order\OrderAfter not found.      
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
 ------ --------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------ 
  Line   contrib/group_content_menu/src/NodeFormAlter.php                              
 ------ ------------------------------------------------------------------------------ 
  42     \Drupal calls should be avoided in classes, use dependency injection instead  
 ------ ------------------------------------------------------------------------------ 

 ------ ------------------------------------------------------------------------------ 
  Line   contrib/group_content_menu/src/Plugin/Group/Relation/GroupMenu.php            
 ------ ------------------------------------------------------------------------------ 
  45     \Drupal calls should be avoided in classes, use dependency injection instead  
 ------ ------------------------------------------------------------------------------ 

 ------ -------------------------------------------------------------------------------------------------------------------------------------- 
  Line   contrib/group_content_menu/src/TranslationSuggestions.php                                                                             
 ------ -------------------------------------------------------------------------------------------------------------------------------------- 
  35     Parameter $job of method Drupal\group_content_menu\TranslationSuggestions::suggestions() has invalid type Drupal\tmgmt\JobInterface.  
  39     Class Drupal\tmgmt\JobItemInterface not found.                                                                                        
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                   
  41     Call to static method load() on an unknown class Drupal\tmgmt_content\Plugin\tmgmt\Source\ContentEntitySource.                        
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                   
  49     \Drupal calls should be avoided in classes, use dependency injection instead                                                          
  60     \Drupal calls should be avoided in classes, use dependency injection instead                                                          
  63     Function tmgmt_job_item_create not found.                                                                                             
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                   
 ------ -------------------------------------------------------------------------------------------------------------------------------------- 
                                                                                                                     
 [ERROR] Found 28 errors                                                                                                

I ran mine locally with level 5, but the gitlab CI seems to produce slightly different results.
The above is a good starting point however and if anything is left those can be fixed too when the CI reports them.

Steps to reproduce

Run the phpstan command on the module.

Proposed resolution

Fix the errors

Remaining tasks

Fix the errors
Test
Review
Merge

User interface changes

None

API changes

None

Data model changes

None

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom the_g_bomb

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

Comments & Activities

Not all content is available!

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

No activities found.

Production build 0.71.5 2024