phpstan: [Bug] Version 0.12.12 and baseline
It might be me doing something wrong. But I’ve got issues running baseline with version 0.12.12.
➜ happyr git:(phpstan) ✗ phpstan --version
PHPStan - PHP Static Analysis Tool 0.12.12
➜ happyr git:(phpstan) ✗ phpstan clear-result-cache
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
Result cache cleared from directory:
/var/folders/38/5p1d21_d5m565304nl8t8qq00000gn/T/phpstan
➜ happyr git:(phpstan) ✗ phpstan analyze --error-format baselineNeon > phpstan-baseline.neon
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
2525/2525 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
➜ happyr git:(phpstan) ✗ phpstan analyze
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
2525/2525 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ ----------------------------------------------------------------------------------------------
Line App/DoctrineMigrations/Version20151110150236.php
------ ----------------------------------------------------------------------------------------------
24 Class Doctrine\ORM\EntityManager referenced with incorrect case: Doctrine\Orm\EntityManager.
------ ----------------------------------------------------------------------------------------------
[ERROR] Found 1 error
If I update baseline again, it will work.
➜ happyr git:(phpstan) ✗ phpstan analyze --error-format baselineNeon > phpstan-baseline.neon
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
2525/2525 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
➜ happyr git:(phpstan) ✗ phpstan analyze
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
2525/2525 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] No errors
But if I clear the cache I get more issues:
➜ happyr git:(phpstan) ✗ phpstan clear-result-cache
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
^[[AResult cache cleared from directory:
/var/folders/38/5p1d21_d5m565304nl8t8qq00000gn/T/phpstan
➜ happyr git:(phpstan) ✗
➜ happyr git:(phpstan) ✗ phpstan analyze
Note: Using configuration file /Users/tobias/Workspace/PHPStorm/happyr/phpstan.neon.dist.
2525/2525 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ ----------------------------------------------------------------------------------------------------------------------
Line App/DoctrineMigrations/Version20131120152300.php
------ ----------------------------------------------------------------------------------------------------------------------
23 Property Application\Migrations\Version20131120152300::$em has unknown class Doctrine\Orm\EntityManager as its type.
------ ----------------------------------------------------------------------------------------------------------------------
------ ----------------------------------------------------------------------------------------------------------------------
Line App/DoctrineMigrations/Version20150902154240.php
------ ----------------------------------------------------------------------------------------------------------------------
24 Property Application\Migrations\Version20150902154240::$em has unknown class Doctrine\Orm\EntityManager as its type.
------ ----------------------------------------------------------------------------------------------------------------------
------ ----------------------------------------------------------------------------------------------
Line App/DoctrineMigrations/Version20151110150236.php
------ ----------------------------------------------------------------------------------------------
24 Class Doctrine\ORM\EntityManager referenced with incorrect case: Doctrine\Orm\EntityManager.
------ ----------------------------------------------------------------------------------------------
[ERROR] Found 3 errors
Here is my config file.
includes:
- ./phpstan-baseline.neon
parameters:
level: 5
reportUnmatchedIgnoredErrors: false
autoload_directories:
- bin/.phpunit/phpunit-8.3-0/src
- %currentWorkingDirectory%/src/App/DoctrineMigrations/
paths:
- src
It is only complaining about files in the DoctrineMigrations folder.
Note that I did not change any files or run any commands but the ones I posted here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 36 (18 by maintainers)
Wow, you’re awesome, this is pretty actionable info 😊 I’ll think about it.
@rainbow-alex This should no longer happen on dev-master 😃 Feel free to try it.
@ondrejmirtes I’ve nailed it down to a minimal case. Took a while, but in the end the cause is pretty obvious.
When phpstan encounters a classname in the incorrect case, two things can happen:
So unfortunately, the errors emitted depend on the order in which files are scanned/loaded. Parallel analysis makes this more likely to occur, but it’s not the root cause. You can reproduce the issue with these files and commands:
Aardvark.php
CaseSensitiveClassName.php
Zygote.php:
phpstan.neon
I’m not sure what the right fix is here. Class names are not case sensitive but autoloaders usually are. I suppose you could check at the very end of all analysis if a missing class turns out to be defined after all and emit an additional, non-baseline error?