thephpleague / csv

CSV data manipulation made easy in PHP
https://csv.thephpleague.com
MIT License
3.34k stars 336 forks source link

PHPStan errors with versions 9.9 and 9.10 #496

Closed earthiverse closed 1 year ago

earthiverse commented 1 year ago
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!

nyamsprod commented 1 year ago

@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

earthiverse commented 1 year ago

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!