Fix the issues reported by PHPStan

Created on 17 November 2023, 7 months ago
Updated 26 November 2023, 7 months ago

Problem/Motivation

As a part of enabling Gitlab CI integration Issue 3402400 📌 Adopt GitlabCi Needs review :
Failed pipeline: https://git.drupalcode.org/issue/geofield-3402400/-/jobs/354768

$ php vendor/bin/phpstan analyze $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME $PHPSTAN_CONFIGURATION --no-progress || EXIT_CODE=$?
 ------ ------------------------------------------------------------------------------ 
  Line   src/Feeds/Target/Geofield.php                                                 
 ------ ------------------------------------------------------------------------------ 
  21     Class Drupal\geofield\Feeds\Target\Geofield extends unknown class             
         Drupal\feeds\Plugin\Type\Target\FieldTargetBase.                              
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols           
  50     Access to an undefined property                                               
         Drupal\geofield\Feeds\Target\Geofield::$targetDefinition.                     
         💡 Learn more:                                                                
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property      
  53     Drupal\geofield\Feeds\Target\Geofield::__construct() calls                    
         parent::__construct() but Drupal\geofield\Feeds\Target\Geofield does          
         not extend any class.                                                         
  60     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
  72     Call to static method createFromFieldDefinition() on an unknown class         
         Drupal\feeds\FieldTargetDefinition.                                           
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols           
  103    Caught class Drupal\feeds\Exception\EmptyFeedException not found.             
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols           
  141    Instantiated class Drupal\feeds\Exception\EmptyFeedException not              
         found.                                                                        
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols           
  150    Drupal\geofield\Feeds\Target\Geofield::getSummary() calls                     
         parent::getSummary() but Drupal\geofield\Feeds\Target\Geofield does           
         not extend any class.                                                         
  153    Call to an undefined method                                                   
         Drupal\geofield\Feeds\Target\Geofield::t().                                   
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/Field/FieldFormatter/GeofieldDefaultFormatter.php                  
 ------ ------------------------------------------------------------------------------ 
  80     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ --------------------------------------------------------------------------------- 
  Line   src/Plugin/Field/FieldFormatter/LatLonFormatter.php                              
 ------ --------------------------------------------------------------------------------- 
  131    Parameter $point of method                                                       
         Drupal\geofield\Plugin\Field\FieldFormatter\LatLonFormatter::getDmsComponents()  
         has invalid type Point.                                                          
 ------ --------------------------------------------------------------------------------- 
 ------ --------------------------------------------------------------------- 
  Line   src/Plugin/Field/FieldType/GeofieldItem.php                          
 ------ --------------------------------------------------------------------- 
  201    Class Geometry not found.                                            
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
 ------ --------------------------------------------------------------------- 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/Field/FieldWidget/GeofieldBaseWidget.php                           
 ------ ------------------------------------------------------------------------------ 
  93     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/GeofieldBackendBase.php                                            
 ------ ------------------------------------------------------------------------------ 
  62     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/GeofieldProximitySource/ContextProximityFilter.php                 
 ------ ------------------------------------------------------------------------------ 
  40     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/GeofieldProximitySource/OriginFromProximityFilter.php              
 ------ ------------------------------------------------------------------------------ 
  45     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ---------------------------------------------------------------------- 
  Line   src/Plugin/GeofieldProximitySourceBase.php                            
 ------ ---------------------------------------------------------------------- 
  89     \Drupal calls should be avoided in classes, use dependency injection  
         instead                                                               
 ------ ---------------------------------------------------------------------- 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/Validation/Constraint/GeoConstraintValidator.php                   
 ------ ------------------------------------------------------------------------------ 
  37     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ -------------------------------------------------------------------------- 
  Line   src/Plugin/diff/Field/GeofieldFieldBuilder.php                            
 ------ -------------------------------------------------------------------------- 
  19     Class Drupal\geofield\Plugin\diff\Field\GeofieldFieldBuilder extends      
         unknown class Drupal\diff\Plugin\diff\Field\CoreFieldBuilder.             
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols       
  33     Access to an undefined property                                           
         Drupal\geofield\Plugin\diff\Field\GeofieldFieldBuilder::$renderer.        
         💡 Learn more:                                                            
            https://phpstan.org/blog/solving-phpstan-access-to-undefined-property  
 ------ -------------------------------------------------------------------------- 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/migrate/process/GeoField.php                                       
 ------ ------------------------------------------------------------------------------ 
  40     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
  77     Class Geometry not found.                                                     
         💡 Learn more at https://phpstan.org/user-guide/discovering-symbols           
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/migrate/process/GeofieldLatLon.php                                 
 ------ ------------------------------------------------------------------------------ 
  40     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/migrate/process/GeofieldWKT.php                                    
 ------ ------------------------------------------------------------------------------ 
  40     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/views/argument/GeofieldProximityArgument.php                       
 ------ ------------------------------------------------------------------------------ 
  138    Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/views/field/GeofieldProximityField.php                             
 ------ ------------------------------------------------------------------------------ 
  75     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/views/filter/GeofieldProximityFilter.php                           
 ------ ------------------------------------------------------------------------------ 
  153    Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 
 ------ ------------------------------------------------------------------------------ 
  Line   src/Plugin/views/sort/GeofieldProximitySort.php                               
 ------ ------------------------------------------------------------------------------ 
  74     Unsafe usage of new static().                                                 
         💡 See:                                                                       
            https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static  
 ------ ------------------------------------------------------------------------------ 

Steps to reproduce

todo Provide command.

Proposed resolution

Fix all issues, or mute them, and enable check in gitlab-ci.yml

Remaining tasks

todo Provide tasks.

📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇷🇺Russia zniki.ru

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

Merge Requests

Comments & Activities

  • Issue created by @zniki.ru
  • Merge request !24Issue #3402434: fix phpstan → (Merged) created by zniki.ru
  • Status changed to Needs work 7 months ago
  • 🇷🇺Russia zniki.ru

    Draft PR created.
    Needs to find how to fix this

     ------ -------------------------------------------------------------------------------------------------------------------- 
      Line   src/Feeds/Target/Geofield.php                                                                                       
     ------ -------------------------------------------------------------------------------------------------------------------- 
      21     Class Drupal\geofield\Feeds\Target\Geofield extends unknown class Drupal\feeds\Plugin\Type\Target\FieldTargetBase.  
             💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                 
     ------ -------------------------------------------------------------------------------------------------------------------- 
    
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
      Line   src/Plugin/diff/Field/GeofieldFieldBuilder.php                                                                                      
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
      19     Class Drupal\geofield\Plugin\diff\Field\GeofieldFieldBuilder extends unknown class Drupal\diff\Plugin\diff\Field\CoreFieldBuilder.  
             💡 Learn more at https://phpstan.org/user-guide/discovering-symbols                                                                 
    
    

    These classes from feeds and diff modules.

  • 🇮🇹Italy itamair

    Please rebase this MR to the last commits in the 8.x-1.x branch. I removed PHPSTAN files and set to Skip the PHPSTAN from the .gitlab-ci.yml, as I am not really aware of it, and those where reporting many errors related to unknown classes refrenced, such as \Geometry and \Point (of course) that are coming from the itamair/geophp library.

    BUT ... do we really need to implement PHPStan (with all its eventual exceptions) in the Geofield module.
    Aren't we adding to much complexities and overhand in code quality checks?
    Isn't phpcs (with Drupal standard) quite enough??

  • 🇮🇹Italy itamair

    Hey @zniki.ru thanks so much for the great contribution here, but also on the Gilab CI integration, and related PHPCS and EsLint code quality checks ... that I already merged in the dev branch.

    I wasn't aware about this PhpStan integration, and well ... yes it might be cool to also enable this in the Geofield module.
    I made a couple of attempts / commits to get rid of the remaining errors (screenshot attached) that should be skipped I guess (as they are not errors), but I couldn't really figure out how to amend the phpstan-baseline.neon file to make it happen, and have an all green baseline scenario.

    You are really welcome if you find a solution for this, also, and if you indeed think / see this is a nice additional quality check integration for the Geofield module, rather than an additional complexity, to slow down the further development of the module.

  • 🇷🇺Russia zniki.ru

    I am also trying to get familiar with PHPStan and I already asked @mglaman to help on this issue, you can see Matt's feedback in the MR.
    Maybe we can try to reach Matt again in order help to finalize this issue.

    The easiest way to update phpstan-baseline.neon use version from pipeline artifacts, you can find it in https://git.drupalcode.org/project/geofield/-/jobs/393496/artifacts/browse, but looks like you need to merge changes manually.
    Or you can use --generate-baseline argument to update it.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    26 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update 7 months ago
    26 pass
  • Status changed to Fixed 7 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024