thephpleague/csv

PHPStan errors with versions 9.9 and 9.10

earthiverse opened this issue ยท 2 comments

Q A
Versions 9.8.0 to 9.10.0

Question

When running PHPStan on my project (PHP 8.2) that uses league/csv's Reader and Writer, I get no errors using version 9.8.

I get the following when running on 9.9

 ------ --------------------------------------------------------------------------------------------------------------------- 
  Line   module/GeoData/src/Importer/PreProcessor/JPPostDataPreProcessor.php                                                  
 ------ --------------------------------------------------------------------------------------------------------------------- 
  226    Method GeoData\Importer\PreProcessor\JPPostDataPreProcessor::getReader() has invalid return type League\Csv\Reader.  
  228    Call to static method createFromPath() on an unknown class League\Csv\Reader.                                        
         ๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols                                                  
 ------ --------------------------------------------------------------------------------------------------------------------- 

And I get the following running on 9.10

 ------ --------------------------------------------------------------------------------------------------------------------- 
  Line   module/GeoData/src/Importer/PreProcessor/JPPostDataPreProcessor.php                                                  
 ------ --------------------------------------------------------------------------------------------------------------------- 
  70     Call to static method createFromPath() on an unknown class League\Csv\Writer.                                        
         ๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols                                                  
  153    Call to static method createFromPath() on an unknown class League\Csv\Writer.                                        
         ๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols                                                  
  226    Method GeoData\Importer\PreProcessor\JPPostDataPreProcessor::getReader() has invalid return type League\Csv\Reader.  
  228    Call to static method createFromPath() on an unknown class League\Csv\Reader.                                        
         ๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols                                                  
 ------ --------------------------------------------------------------------------------------------------------------------- 

I was wondering if anyone had any idea why this could be the case. My project works fine with league/csv 9.8.

Thank you!

@earthiverse while I do not think it is a issue around the package, since It also uses PHPStan for code analysis I would refer to the error message you get

๐Ÿ’ก Learn more at https://phpstan.org/user-guide/discovering-symbols

Maybe your application settings is made such as you need to help PHPStan locate the class ๐Ÿค” .

At least from what you provide as information that's what I would look for in the first place.
Hope this will help you.

Cheers

I figured it out!

I had phpVersion: 70430 specified in my phpstan.neon configuration file. Updating it to the PHP version we've upgraded to (phpVersion: 80210) removed the errors.

Thank you!