Fix PHPStan errors

Created on 11 January 2024, 6 months ago
Updated 15 January 2024, 6 months ago

Problem/Motivation

After implementing 📌 Integration with Gitlab CI RTBC PHPStan reporting errors.
You can see it in the pipeline.

Please use phpstan.neon from MR.

 vendor/bin/phpstan analyze modules/contrib/contact_storage/ -c modules/contrib/contact_storage/phpstan.neon 
 ------ ---------------------------------------------- 
  Line   crop.module                                   
 ------ ---------------------------------------------- 
  91     Call to an undefined method                   
         Drupal\Core\Form\FormInterface::getEntity().  
 ------ ---------------------------------------------- 
 ------ --------------------------------------------------------------------- 
  Line   src/CropTypeInterface.php                                            
 ------ --------------------------------------------------------------------- 
  17     PHPDoc tag @var for constant                                         
         Drupal\crop\CropTypeInterface::VALIDATION_REGEXP with type array is  
         incompatible with value '#^[0-9]+:[0-9]+$#'.                         
 ------ --------------------------------------------------------------------- 
 ------ -------------------------------------------------------------------------- 
  Line   src/CropTypeListBuilder.php                                               
 ------ -------------------------------------------------------------------------- 
  92     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$description.                         
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  93     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::getAspectRatio().                     
  103    Variable $image_style in PHPDoc tag @var does not match assigned          
         variable $usage.                                                          
 ------ -------------------------------------------------------------------------- 
 ------ -------------------------------------------------------------------------- 
  Line   src/Entity/Crop.php                                                       
 ------ -------------------------------------------------------------------------- 
  147    Call to an undefined method                                               
         Drupal\Core\Entity\EntityStorageInterface::getCrop().                     
  252    Access to an undefined property                                           
         Drupal\Core\Entity\ContentEntityInterface::$revision_log.                 
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
 ------ -------------------------------------------------------------------------- 
 ------ --------------------------------------------------------------------- 
  Line   src/EntityProviderBase.php                                           
 ------ --------------------------------------------------------------------- 
  17     Method Drupal\crop\EntityProviderBase::label() should return string  
         but return statement is missing.                                     
 ------ --------------------------------------------------------------------- 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Form/CropTypeForm.php                                                     
 ------ ------------------------------------------------------------------------------ 
  29     Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$label.                                   
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  50     Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$description.                             
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  57     Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$aspect_ratio.                            
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  71     Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$soft_limit_width.                        
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  80     Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$soft_limit_height.                       
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  96     Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$hard_limit_width.                        
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  105    Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$hard_limit_height.                       
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  150    Call to an undefined method                                                   
         Symfony\Component\Validator\ConstraintViolationListInterface::getIterator().  
  165    Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$id.                                      
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  166    Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$label.                                   
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  166    Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$label.                                   
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  167    Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$aspect_ratio.                            
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  167    Access to an undefined property                                               
         Drupal\Core\Entity\EntityInterface::$aspect_ratio.                            
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  182    Method Drupal\crop\Form\CropTypeForm::save() should return int but            
         return statement is missing.                                                  
 ------ ------------------------------------------------------------------------------ 
 ------ --------------------------------------------------------------------------------------- 
  Line   src/Plugin/Validation/Constraint/CropTypeAspectRatioValidationConstraintValidator.php  
 ------ --------------------------------------------------------------------------------------- 
  27     Access to an undefined property                                                        
         Symfony\Component\Validator\Constraint::$message.                                      
         💡 Learn more:                                                                         
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property               
 ------ --------------------------------------------------------------------------------------- 
 ------ --------------------------------------------------------------------------------------- 
  Line   src/Plugin/Validation/Constraint/CropTypeMachineNameValidationConstraintValidator.php  
 ------ --------------------------------------------------------------------------------------- 
  27     Access to an undefined property                                                        
         Symfony\Component\Validator\Constraint::$message.                                      
         💡 Learn more:                                                                         
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property               
 ------ --------------------------------------------------------------------------------------- 
 ------ -------------------------------------------------------------------------- 
  Line   tests/src/Functional/CropFunctionalTest.php                               
 ------ -------------------------------------------------------------------------- 
  99     Access to an undefined property                                           
         Drupal\Tests\crop\Functional\CropFunctionalTest::$randomGenerator.        
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  130    Call to an undefined method Traversable<mixed, mixed>::current().         
  176    Variable $crop in PHPDoc tag @var does not match assigned variable        
         $values.                                                                  
 ------ -------------------------------------------------------------------------- 
 ------ -------------------------------------------------------------------------- 
  Line   tests/src/Kernel/CropCRUDTest.php                                         
 ------ -------------------------------------------------------------------------- 
  29     Access to an undefined property                                           
         Drupal\Tests\crop\Kernel\CropCRUDTest::$randomGenerator.                  
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  56     Variable $crop in PHPDoc tag @var does not match assigned variable        
         $values.                                                                  
  68     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::position().                           
  69     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::size().                               
  70     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::anchor().                             
  72     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::setPosition().                        
  73     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::setSize().                            
  75     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::position().                           
  76     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::size().                               
  77     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::anchor().                             
  79     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::setPosition().                        
  80     Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::setSize().                            
  94     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$type.                                
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$entity_id.                           
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$entity_type.                         
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$height.                              
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$uri.                                 
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$width.                               
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$x.                                   
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  98     Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$y.                                   
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
  110    Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::position().                           
  111    Call to an undefined method                                               
         Drupal\Core\Entity\EntityInterface::size().                               
  112    Access to an undefined property                                           
         Drupal\Core\Entity\EntityInterface::$uri.                                 
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
 ------ -------------------------------------------------------------------------- 
 ------ --------------------------------------------------------------- 
  Line   tests/src/Kernel/CropEffectTest.php                            
 ------ --------------------------------------------------------------- 
  91     PHPDoc tag @var has invalid value ($effect                     
         \Drupal\crop\Plugin\ImageEffect\CropEffect): Unexpected token  
         "$effect", expected type at offset 9 on line 1                 
 ------ --------------------------------------------------------------- 
 ------ ---------------------------------------------- 
  Line   tests/src/Kernel/CropEntityProvidersTest.php  
 ------ ---------------------------------------------- 
  51     Variable $provider might not be defined.      
 ------ ----------------------------------------------                                                                             
📌 Task
Status

Needs review

Version

2.0

Component

Code

Created by

🇷🇺Russia zniki.ru

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @zniki.ru
  • Merge request !7Resolve #3413981 "Fix phpstan errors" → (Open) created by zniki.ru
  • Status changed to Needs work 6 months ago
  • 🇷🇺Russia zniki.ru

    I fixed few errors, but there are more to fix.

  • Status changed to Needs review 6 months ago
  • 🇷🇺Russia zniki.ru

    I added to ignore few violations:

    Access to an undefined property Symfony\Component\Validator\Constraint::$message. 
    

    We have same approach acros all the Drupal code base, not sure how to fix it.

    Access to an undefined property Drupal\Core\Entity\ContentEntityInterface::$revision_log.   
    

    Same code used in the \Drupal\node\Entity\Node::preSaveRevision() , also have no clue how to fix it.

    MR is ready for review.

Production build 0.69.0 2024