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

New symfony 6.1 projects can't be inspected using docker image as they rely on PHP 8.1 #7334

Closed
Gyula-Toth opened this issue May 28, 2022 · 6 comments

Comments

@Gyula-Toth
Copy link

Bug report

I've got a project that uses Symfony (a very basic Symfony API used for mocking external services in a local project.
Ever since the 6.1 Symfony release, PHPStan [latest docker image] fails to run for the project.
My theory at the time - seeing that Symfony requires PHP versions have been bumped to 8.1 that this is a language version-specific issue.

To verify this I've cloned a repository, changed the base image to 8.1, and used the newly built image for the same inspection - which worked fine.

I assume We're happy about just bumping the base image to 8.1?

See the following stack trace:

     Internal error: Internal error: syntax error, unexpected token ")" in file /app/mock-server/project/config/bundles.php                                                                                                                  
                                                                                                                                                                                                                                             
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:                                                                                                                                 
     #0 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/app/mock-serve...')                                                                                       
     #1 /app/mock-server/project/vendor/symfony/cache/Adapter/ApcuAdapter.php(21): Composer\Autoload\ClassLoader->loadClass('Symfony\\Compone...')                                                                                           
     #2 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php(571): include('/app/mock-serve...')                                                                                                             
     #3 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/app/mock-serve...')                                                                                       
     #4 [internal function]: Composer\Autoload\ClassLoader->loadClass('Symfony\\Compone...')                                                                                                                                                 
     #5 /app/mock-server/project/vendor/symfony/framework-bundle/FrameworkBundle.php(74): class_exists('Symfony\\Compone...')                                                                                                                
     #6 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php(571): include('/app/mock-serve...')                                                                                                             
     #7 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/app/mock-serve...')                                                                                       
     #8 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadFunctionsSourceLocator.php(28): Composer\Autoload\ClassLoader->loadClass('Symfony\\Bundle\\...')                          
     #9 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(28):                                                                                    
     PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadFunctionsSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector), Object(PHPStan\BetterReflection\Identifier\Identifier))                 
     #10 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/MemoizingSourceLocator.php(33):                                                                                   
     PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector), Object(PHPStan\BetterReflection\Identifier\Identifier))                               
     #11 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/Reflector/DefaultReflector.php(32):                                                                                                  
     PHPStan\BetterReflection\SourceLocator\Type\MemoizingSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector), Object(PHPStan\BetterReflection\Identifier\Identifier))                               
     #12 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php(45): PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass('Symfony\\Bundle\\...')                
     #13 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(151): PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass('Symfony\\Bundle\\...')      
     #14 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(34): PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass('Symfony\\Bundle\\...')          
     #15 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Classes/ClassConstantRule.php(86): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass('Symfony\\Bundle\\...')                               
     #16 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(102): PHPStan\Rules\Classes\ClassConstantRule->processNode(Object(PhpParser\Node\Expr\ClassConstFetch), Object(PHPStan\Analyser\MutatingScope))  
     #17 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2394): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Expr\ClassConstFetch),                               
     Object(PHPStan\Analyser\MutatingScope))                                                                                                                                                                                                 
     #18 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1418): PHPStan\Analyser\NodeScopeResolver->callNodeCallbackWithExpression(Object(Closure), Object(PhpParser\Node\Expr\ClassConstFetch),     
     Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Analyser\ExpressionContext))                                                                                                                                                     
     #19 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1845): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Expr\ClassConstFetch),                                     
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\ExpressionContext))                                                                                                                                    
     #20 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1835): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Expr\ArrayItem), Object(PHPStan\Analyser\MutatingScope),   
     Object(Closure), Object(PHPStan\Analyser\ExpressionContext))                                                                                                                                                                            
     #21 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(500): PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node\Expr\Array_), Object(PHPStan\Analyser\MutatingScope),       
     Object(Closure), Object(PHPStan\Analyser\ExpressionContext))                                                                                                                                                                            
     #22 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(294): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope),      
     Object(Closure))                                                                                                                                                                                                                        
     #23 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(189): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))                           
     #24 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(143): PHPStan\Analyser\FileAnalyser->analyseFile('/app/mock-serve...', Array, Object(PHPStan\Rules\Registry), NULL)                              
     #25 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)                                            
     #26 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_f22c92df8\Evenement\EventEmitter->emit('data', Array)                                                                  
     #27 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_f22c92df8\Clue\React\NDJson\Decoder->handleData(Array)                                            
     #28 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_f22c92df8\Evenement\EventEmitter->emit('data', Array)                                                                           
     #29 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_f22c92df8\React\Stream\Util::_PHPStan_f22c92df8\React\Stream\{closure}('{"action":"anal...')      
     #30 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_f22c92df8\Evenement\EventEmitter->emit('data', Array)                                                          
     #31 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_f22c92df8\React\Stream\DuplexResourceStream->handleData(Resource id #3733)                                     
     #32 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_f22c92df8\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)                                        
     #33 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(106): _PHPStan_f22c92df8\React\EventLoop\StreamSelectLoop->run()                                                                                 
     #34 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_f22c92df8\Symfony\Component\Console\Input\ArgvInput),                  
     Object(_PHPStan_f22c92df8\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                                              
     #35 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(856):                                                                                                                                   
     _PHPStan_f22c92df8\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_f22c92df8\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_f22c92df8\Symfony\Component\Console\Output\ConsoleOutput))                      
     #36 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_f22c92df8\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand),                     
     Object(_PHPStan_f22c92df8\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_f22c92df8\Symfony\Component\Console\Output\ConsoleOutput))                                                                                        
     #37 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                                                                                                                   
     _PHPStan_f22c92df8\Symfony\Component\Console\Application->doRun(Object(_PHPStan_f22c92df8\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_f22c92df8\Symfony\Component\Console\Output\ConsoleOutput))                        
     #38 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(96): _PHPStan_f22c92df8\Symfony\Component\Console\Application->run()                                                                                               
     #39 phar:///composer/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(97): _PHPStan_f22c92df8\{closure}()                                                                                                                                
     #40 /composer/vendor/phpstan/phpstan/phpstan(8): require('phar:///compose...')                                                                                                                                                          
     #41 /composer/vendor/bin/phpstan(117): include('/composer/vendo...')                                                                                                                                                                    
     #42 {main}                                                                                                                                                                                                                              
     Child process error (exit code 1):                                                                                                                                                                                                      
@mergeable
Copy link

mergeable bot commented May 28, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

Gyula-Toth added a commit to Gyula-Toth/phpstan that referenced this issue May 28, 2022
@ondrejmirtes
Copy link
Member

I'd say the Docker image is really needed only in some special scenarios. You can run PHPStan in the same environment you run your app, be it your Docker image or directly on your host computer.

@Gyula-Toth
Copy link
Author

Gyula-Toth commented May 28, 2022

I'd say the Docker image is really needed only in some special scenarios. You can run PHPStan in the same environment you run your app, be it your Docker image or directly on your host computer.

Yes, although technically you can run it on your host computer, if there are multiple developers on the project, it's important to ensure that all of them have the same setup and environment, lest you start to encounter issues of 'well, it works on my machine'.

Plus it's a lot easier to tell new developers to install docker, and then everything else will work as per documented in the project, [and then have a docker command in the projects docker-compose.yml] rather than to make them set up all tools and inspections with different profiles in their host machine.

For that, a docker is very useful. For instance, we have 6 different apps running solely in a single project.

PHPStan inspections passing is one of the requirements we set out to impose on the developers before creating a PR.
Running this on the host container is also a suboptimal option, as you'd have to alter 6 different images, and run 6 different commands in a daisy chain to get the same result as you could achieve with a single docker command. This inspection then also happens in a CD/CI chain in a build box, and you'd have to make sure that no inspection / and dev tools are getting released in your prod ready app image. Even more, it's also important to have these inspections happen in the same reproducible way / with the same setup in all stages of release/development.

For these reasons, I feel that using the docker image is the ideal way for our needs.

@ondrejmirtes
Copy link
Member

I can't change the base image of the currently used tags for backward compatibility reasons, but I introduced new tags that use PHP 8.1. See release notes: https://github.com/phpstan/phpstan/releases/tag/1.7.3

@Wirone
Copy link
Contributor

Wirone commented May 29, 2022

Yes, although technically you can run it on your host computer, if there are multiple developers on the project, it's important to ensure that all of them have the same setup and environment, lest you start to encounter issues of 'well, it works on my machine'.

And that's why you should have your own Docker setup in the project, for running it locally within common runtime across all developers' computers. But it should be your app's runtime, not basic PHPStan Docker image 🙂 Same image could be built in CI/CD pipeline and all checks could be run on it. It's even more consistent then 😉

But anyway, great to see @ondrejmirtes offering image and now it's even better 😁

@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 Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants