PHPStan errors when developing locally

Created on 29 April 2025, about 1 month ago

Overview

I thought this was just me, but I discovered that @tedbow, @wim leers, @penyaskito and others are also running into problems running PHPStan locally. Some weeks ago the output used to be clean, but now I get errors; however this isn't replicated on CI:

 ------ ---------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/ClientDataToEntityConverter.php                                                                                               
 ------ ---------------------------------------------------------------------------------------------------------------------------------- 
  248    Parameter #1 $id of method Drupal\Core\Entity\EntityStorageInterface::loadUnchanged() expects int|string, int|string|null given.  
 ------ ---------------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/src/Kernel/ApiAutoSaveControllerTest.php                                                                                      
 ------ ------------------------------------------------------------------------------------------------------------------------------------ 
  554    Parameter #1 $id of method Drupal\Core\Entity\EntityStorageBase::loadUnchanged() expects int|string, int|string|null given.         
  555    Parameter #1 $id of method Drupal\Core\Entity\EntityStorageBase::loadUnchanged() expects int|string, int|string|null given.         
  556    Parameter #1 $id of method Drupal\Core\Entity\ContentEntityStorageBase::loadUnchanged() expects int|string, int|string|null given.  
  677    Parameter #1 $id of method Drupal\Core\Entity\ContentEntityStorageBase::loadUnchanged() expects int|string, int|string|null given.  
  682    Parameter #1 $id of method Drupal\Core\Entity\EntityStorageBase::loadUnchanged() expects int|string, int|string|null given.         
  683    Parameter #1 $id of method Drupal\Core\Entity\EntityStorageBase::loadUnchanged() expects int|string, int|string|null given.         
 ------ ------------------------------------------------------------------------------------------------------------------------------------ 

 ------ --------------------------------------------------------------------------------------------------------------------------- 
  Line   tests/src/Kernel/Config/AssetLibraryValidationTest.php                                                                     
 ------ --------------------------------------------------------------------------------------------------------------------------- 
  195    Method Drupal\Tests\experience_builder\Kernel\Config\AssetLibraryValidationTest::testMachineNameLength() overrides method  
         Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase::testMachineNameLength() but misses parameter #1 $prefix.    
 ------ --------------------------------------------------------------------------------------------------------------------------- 

 ------ ------------------------------------------------------------------------------------------------------------------------------------ 
  Line   tests/src/Kernel/NodeTemplatesTest.php                                                                                              
 ------ ------------------------------------------------------------------------------------------------------------------------------------ 
  142    Parameter #1 $id of method Drupal\Core\Entity\ContentEntityStorageBase::loadUnchanged() expects int|string, int|string|null given.  
 ------ ------------------------------------------------------------------------------------------------------------------------------------ 

Let's investigate why this is and try to make it consistent for everyone.

Proposed resolution

?

User interface changes

🐛 Bug report
Status

Active

Version

0.0

Component

Miscellaneous

Created by

🇬🇧United Kingdom longwave UK

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

Comments & Activities

  • Issue created by @longwave
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Different set for me, on b0ef5921b5fdc7575d9418db1ebefa1f90555da5 of Drupal core's 11.1.x branch:

    $ php vendor/bin/phpstan analyze modules/contrib/experience_builder --memory-limit=256M --configuration=modules/contrib/experience_builder/phpstan.neon  -vvv
    Result cache not used because the metadata do not match: projectConfig, composerLocks, composerInstalled
     306/306 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 10 secs/10 secs
    
    Result cache is saved.
     ------ --------------------------------------- 
      Line   src/Plugin/BlockManager.php            
     ------ --------------------------------------- 
      25     Plugin definitions cannot be altered.  
     ------ --------------------------------------- 
    
     ------ --------------------------------------- 
      Line   src/Plugin/ComponentPluginManager.php  
     ------ --------------------------------------- 
      30     Plugin definitions cannot be altered.  
     ------ --------------------------------------- 
    
     ------ ------------------------------------------------------ 
      Line   tests/src/Kernel/ClientDataToEntityConverterTest.php  
     ------ ------------------------------------------------------ 
      346    Plugin definitions cannot be altered.                 
     ------ ------------------------------------------------------ 
    
     ------ --------------------------------------------------------------------- 
      Line   tests/src/Kernel/Entity/PageMetatagIntegrationTest.php               
     ------ --------------------------------------------------------------------- 
      141    Function metatag_get_tags_from_route not found.                      
             🪪  function.notFound                                                
             💡 Learn more at https://phpstan.org/user-guide/discovering-symbols  
     ------ --------------------------------------------------------------------- 
    
     ------ -------------------------------------------------------------------------------------------------------------------------------- 
      Line   tests/src/Unit/Access/XbHttpApiEligibleConfigEntityAccessCheckTest.php                                                          
     ------ -------------------------------------------------------------------------------------------------------------------------------- 
      26     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\Core\Routing\RouteMatchInterface>::getParameter().          
             🪪  method.notFound                                                                                                             
      42     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\Core\Config\Entity\ConfigEntityTypeInterface>::getClass().  
             🪪  method.notFound                                                                                                             
      45     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\Core\Entity\EntityTypeManagerInterface>::getDefinition().   
             🪪  method.notFound                                                                                                             
     ------ -------------------------------------------------------------------------------------------------------------------------------- 
    
     ------ ------------------------------------------------------------------------------------------------------------------------------------------ 
      Line   tests/src/Unit/DataType/ComponentInputsTest.php                                                                                           
     ------ ------------------------------------------------------------------------------------------------------------------------------------------ 
      46     Call to an undefined method                                                                                                               
             Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\Plugin\DataType\ComponentTreeStructure>::getComponentId().                     
             🪪  method.notFound                                                                                                                       
      47     Call to an undefined method                                                                                                               
             Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\Plugin\DataType\ComponentTreeStructure>::getComponentSource().                 
             🪪  method.notFound                                                                                                                       
      50     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\Plugin\Field\FieldType\ComponentTreeItem>::get().  
             🪪  method.notFound                                                                                                                       
      51     Call to an undefined method                                                                                                               
             Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\Plugin\Field\FieldType\ComponentTreeItem>::onChange().                         
             🪪  method.notFound                                                                                                                       
      68     Call to an undefined method                                                                                                               
             Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\Plugin\DataType\ComponentTreeStructure>::getComponentSource().                 
             🪪  method.notFound                                                                                                                       
      69     Call to an undefined method                                                                                                               
             Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\ComponentSource\ComponentSourceInterface>::requiresExplicitInput().            
             🪪  method.notFound                                                                                                                       
      75     Call to an undefined method                                                                                                               
             Prophecy\Prophecy\ObjectProphecy<Drupal\experience_builder\ComponentSource\ComponentSourceInterface>::requiresExplicitInput().            
             🪪  method.notFound                                                                                                                       
     ------ ------------------------------------------------------------------------------------------------------------------------------------------ 
    
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
      Line   tests/src/Unit/EntityHandlers/ContentCreatorVisibleXbConfigEntityAccessControlHandlerTest.php                                       
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
      38     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\Core\Cache\Context\CacheContextsManager>::assertValidTokens().  
             🪪  method.notFound                                                                                                                 
      75     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\Core\Cache\Context\CacheContextsManager>::assertValidTokens().  
             🪪  method.notFound                                                                                                                 
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
    
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
      Line   tests/src/Unit/EntityHandlers/XbConfigEntityAccessControlHandlerTest.php                                                            
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
      35     Call to an undefined method Prophecy\Prophecy\ObjectProphecy<Drupal\Core\Cache\Context\CacheContextsManager>::assertValidTokens().  
             🪪  method.notFound                                                                                                                 
     ------ ------------------------------------------------------------------------------------------------------------------------------------ 
    
                                                                                                                            
     [ERROR] Found 17 errors                                                                                                
                                                                                                                            
    
    PHP runtime version: 8.3.19
    PHP version for analysis: 8.3 (from config.platform.php in composer.json)
    
    PHPStan version: 1.12.12
    PHPStan running from:
    /Users/wim.leers/core/vendor/phpstan/phpstan
    
    Extension installer:
    composer/composer: 2.8.3
    composer/pcre: 3.3.2
    mglaman/phpstan-drupal: 1.3.1
    phpstan/phpstan-deprecation-rules: 1.2.1
    phpstan/phpstan-phpunit: 1.4.1
    
    Discovered Composer project root:
    /Users/wim.leers/core
    
    Parallel processing scheduler:
    # of detected CPU cores:   10
    # of analysed files:       306
    # of jobs:                 16
    # of spawned processes:    8
    
    Elapsed time: 14 seconds
    Used memory: 1.52 GB
    wim.leers at MacBookPro-WimLeers in ~/core on 11.1.x*
    $ php vendor/bin/phpstan analyze modules/contrib/experience_builder --memory-limit=256M --configuration=modules/contrib/experience_builder/phpstan.neo
    
  • 🇬🇧United Kingdom longwave UK

    The issues in the IS are because I was still on 11.x instead of 11.1 after previously debugging a separate issue with @penyaskito.

    I can fix the errors in #2 by upgrading everything and installing another package:

    $ composer require --dev jangregor/phpstan-prophecy
    ...
    
    $ ../vendor/bin/phpstan analyze modules/contrib/experience_builder --memory-limit=256M --configuration=modules/contrib/experience_builder/phpstan.neon  -vvv
    Result cache not used because the metadata do not match: projectConfig, composerLocks, composerInstalled
     311/311 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% 16 secs/16 secs
    
    Result cache is saved.
    
                                                                                                                            
     [OK] No errors                                                                                                         
                                                                                                                            
    
    PHP runtime version: 8.3.6
    PHP version for analysis: 8.3.6 (from runtime)
    
    PHPStan version: 1.12.25
    PHPStan running from:
    /home/dave/projects/xb/vendor/phpstan/phpstan
    
    Extension installer:
    composer/composer: 2.8.6
    composer/pcre: 3.3.2
    jangregor/phpstan-prophecy: 1.0.2
    mglaman/phpstan-drupal: 1.3.7
    phpstan/phpstan-deprecation-rules: 1.2.1
    phpstan/phpstan-phpunit: 1.4.2
    
    Discovered Composer project root:
    /home/dave/projects/xb
    
    Parallel processing scheduler:
    # of detected CPU cores:   14
    # of analysed files:       311
    # of jobs:                 16
    # of spawned processes:    8
    
    Elapsed time: 17 seconds
    Used memory: 1.62 GB
    

    @Wim can you try installing this and also running composer update to get the latest PHPStan and extensions?

  • 🇬🇧United Kingdom longwave UK

    We should fix the errors in the IS over in 🐛 PHPUnit Next Major tests failing Active as I assume they will pop up on CI over there.

  • 🇬🇧United Kingdom longwave UK

    Bingo, same fails at https://git.drupalcode.org/project/experience_builder/-/jobs/5103955 - will continue over there

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Which 11.1.x commit are you on?

  • 🇬🇧United Kingdom longwave UK

    I currently get no errors on 11.1.2, 11.1.6 or 11.1.x-dev (which matches your commit hash).

    Did you try composer require --dev jangregor/phpstan-prophecy?

    I also have Metatag in composer.json which is likely why I don't get the error about metatag_get_tags_from_route.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I did not. I've been doing

    composer require league/openapi-psr7-validator webflo/drupal-finder devizzent/cebe-php-openapi --dev
    

    per our CONTRIBUTING.md.

    Just did that and … yep, that's it! So we just need to update our CONTRIBUTING.md!

  • @wim-leers opened merge request.
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Just manually stepped through this multiple times, can confirm this makes it work reliably 👍 Thanks, @longwave!

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
    • wim leers committed 328b8a3c on 0.x
      Issue #3521792 by wim leers, longwave: PHPStan errors when developing...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024