Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in StubPhpDocProvider #3885

Closed
greg0ire opened this issue Sep 25, 2020 · 19 comments
Closed

Crash in StubPhpDocProvider #3885

greg0ire opened this issue Sep 25, 2020 · 19 comments

Comments

@greg0ire
Copy link

Bug report

After upgrading my app, I'm getting this mysterious crash:

In StubPhpDocProvider.php line 150:
                                      
  [PHPStan\ShouldNotHappenException]  
  Internal error.                     
                                      

Exception trace:
  at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubPhpDocProvider.php:150
 PHPStan\PhpDoc\StubPhpDocProvider->initializeKnownElements() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubPhpDocProvider.php:133
 PHPStan\PhpDoc\StubPhpDocProvider->isKnownClass() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubPhpDocProvider.php:56
 PHPStan\PhpDoc\StubPhpDocProvider->findClassPhpDoc() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Reflection/BetterReflection/BetterReflectionProvider.php:113
 PHPStan\Reflection\BetterReflection\BetterReflectionProvider->getClass() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Rules/ClassCaseSensitivityCheck.php:31
 PHPStan\Rules\ClassCaseSensitivityCheck->checkClassNames() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Rules/Classes/ExistingClassesInInterfaceExtendsRule.php:34
 PHPStan\Rules\Classes\ExistingClassesInInterfaceExtendsRule->processNode() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Analyser/FileAnalyser.php:68
 PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:278
 PHPStan\Analyser\NodeScopeResolver->processStmtNode() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Analyser/NodeScopeResolver.php:193
 PHPStan\Analyser\NodeScopeResolver->processNodes() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Analyser/FileAnalyser.php:148
 PHPStan\Analyser\FileAnalyser->analyseFile() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/PhpDoc/StubValidator.php:78
 PHPStan\PhpDoc\StubValidator->validate() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Command/AnalyseApplication.php:47
 PHPStan\Command\AnalyseApplication->analyse() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/src/Command/AnalyseCommand.php:148
 PHPStan\Command\AnalyseCommand->execute() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Command/Command.php:228
 _HumbugBoxeae286054244\Symfony\Component\Console\Command\Command->run() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Application.php:852
 _HumbugBoxeae286054244\Symfony\Component\Console\Application->doRunCommand() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Application.php:235
 _HumbugBoxeae286054244\Symfony\Component\Console\Application->doRun() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/vendor/symfony/console/Application.php:136
 _HumbugBoxeae286054244\Symfony\Component\Console\Application->run() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/bin/phpstan:76
 _HumbugBoxeae286054244\{closure}() at phar:///tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan/bin/phpstan:77
 require() at /tmp/phpstan-crash/vendor/phpstan/phpstan/phpstan:6

Code snippet that reproduces the problem

git clone  git@github.com:greg0ire/phpstan-crash.git
cd phpstan-crash
composer install --no-scripts
vendor/bin/phpstan --ansi analyse --no-progress -c phpstan.neon -vvv

Expected output

Some errors, but no crash.

@mergeable
Copy link

mergeable bot commented Sep 25, 2020

This bug report is missing a link to reproduction on phpstan.org.
It will most likely be closed after manual review.

@enumag
Copy link
Contributor

enumag commented Sep 28, 2020

Ran into this error as well. The last version that works for me is 0.12.42. Versions 43-45 all throw this error.

@canvural
Copy link
Contributor

Maybe it is related to https://github.com/zircote/swagger-php again? There were few issues with that package before.

@greg0ire
Copy link
Author

@canvural I forgot to mention it, but IIRC it is related to that package.

@canvural
Copy link
Contributor

@greg0ire So did you open an issue there?

@greg0ire
Copy link
Author

Why should I? Phpstan is not supposed to crash with that message, no matter what it analyzes, is it?

@arjanfrans
Copy link

Ran into the same problem. Using version 0.12.45.

@ondrejmirtes
Copy link
Member

Are you all also using swagger-php?

@canvural
Copy link
Contributor

If you don't include the phpstan-symfony extension you get this error:

------ ------------------------------------------------ 
  Line   tests/Behat/DemoContext.php                     
 ------ ------------------------------------------------ 
  5      Syntax error, unexpected T_ATTRIBUTE on line 5  
 ------ ------------------------------------------------

Looks like it was attempted to fix, but decided it's an issue with php-parser

@arjanfrans
Copy link

@ondrejmirtes Yes.

@enumag
Copy link
Contributor

enumag commented Sep 28, 2020

@ondrejmirtes It appears to be an indirect dependency in my project too.

@enumag
Copy link
Contributor

enumag commented Sep 28, 2020

@canvural That issue seems to have been solved by php-parser 4.10.2 and completely unrelated. If I remove phpstan-symfony from my project I still get the same error with StubPhpDocProvider.

@greg0ire
Copy link
Author

IIIRC removing this part of the extension file fixes the issue:

	stubFiles:
		- stubs/ChoiceLoaderInterface.stub
		- stubs/Constraint.stub
		- stubs/ContainerBuilder.stub
		- stubs/EventSubscriberInterface.stub
		- stubs/ExtensionInterface.stub
		- stubs/FormBuilderInterface.stub
		- stubs/FormInterface.stub
		- stubs/FormTypeInterface.stub
		- stubs/FormView.stub
		- stubs/HeaderBag.stub
		- stubs/Process.stub
		- stubs/Session.stub

So does downgrading the zircote lib.

@greg0ire
Copy link
Author

@ondrejmirtes how do you usually debug that kind of stuff? I pushed a new commit that allows to reproduce the issue with phpstan/phpstan-src, but maybe there is a simpler way, like extracting the phar?

There is an extra instruction that is needed when using that method: sed -i 's/\.\.\/vendor\/autoload/..\/..\/..\/..\/vendor\/autoload/' vendor/phpstan/phpstan-src/bin/phpstan
See greg0ire/phpstan-crash@138866a

@ondrejmirtes
Copy link
Member

Looks like this bug is going to be solved by upgrading nikic/php-parser to 4.10.2. I'm gonna push a release soon.

@ondrejmirtes
Copy link
Member

Fixed by: phpstan/phpstan-src@e7203bc

PHPStan 0.12.46 will be out shortly after.

@ondrejmirtes
Copy link
Member

And it's out :) https://github.com/phpstan/phpstan/releases/tag/0.12.46

@greg0ire
Copy link
Author

Works great! Thanks!

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants