Skip to content

Using consoleApplicationLoader with bin/console causes a phpstan internal error #330

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

Closed
DAcodedBEAT opened this issue Feb 14, 2023 · 5 comments

Comments

@DAcodedBEAT
Copy link

I tried to enable consoleApplicationLoader: bin/console in phpstan.neon config file and received the following error a few times for the Command classes.

 Internal error: Internal error: Return value of PHPStan\Symfony\ConsoleApplicationResolver::getConsoleApplication() must be an instance of Symfony\Component\Console\Application or null, instance   
     of Closure returned in file <my-application-path>/src/Command/MySymfonyCommand.php                                                                                     
                                                                                                                                                                                                          
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:                                                                                              
     #0 <my-application-path>/vendor/phpstan/phpstan-symfony/src/Symfony/ConsoleApplicationResolver.php(54): PHPStan\Symfony\ConsoleApplicationResolver->getConsoleApplication()  
     #1 <my-application-path>/vendor/phpstan/phpstan-symfony/src/Type/Symfony/InputInterfaceGetOptionDynamicReturnTypeExtension.php(59):                                          
     PHPStan\Symfony\ConsoleApplicationResolver->findCommands(Object(PHPStan\Reflection\ClassReflection))                                                                                                 
     #2 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3367):                                                                    
     PHPStan\Type\Symfony\InputInterfaceGetOptionDynamicReturnTypeExtension->getTypeFromMethodCall(Object(PHPStan\Reflection\ResolvedMethodReflection), Object(PhpParser\Node\Expr\MethodCall),           
     Object(PHPStan\Analyser\MutatingScope))                                                                                                                                                              
     #3 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1365):                                                                    
     PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\ObjectType), 'getOption', Object(PhpParser\Node\Expr\MethodCall))                                                           
     #4 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1371): PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()       
     #5 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(557): PHPStan\Analyser\MutatingScope->resolveType('$input->getOpti...',   
     Object(PhpParser\Node\Expr\MethodCall))                                                                                                                                                              
     #6 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(777):                                                                     
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\MethodCall))                                                                                                                      
     #7 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(557): PHPStan\Analyser\MutatingScope->resolveType('$days = $input-...',   
     Object(PhpParser\Node\Expr\Assign))                                                                                                                                                                  
     #8 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1446):                                                                
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\Assign))                                                                                                                          
     #9 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(557):                                                                 
     PHPStan\Analyser\NodeScopeResolver->findEarlyTerminatingExpr(Object(PhpParser\Node\Expr\Assign), Object(PHPStan\Analyser\MutatingScope))                                                             
     #10 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Expression), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))      
     #11 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(521):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure),                                        
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                                           
     #12 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer),                   
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                                           
     #13 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(599):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope), Object(PHPStan\Node\ClassStatementsGatherer),                
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                                           
     #14 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))          
     #15 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(571):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure),                                         
     Object(PHPStan\Analyser\StatementContext))                                                                                                                                                           
     #16 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(327):                                                                
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))      
     #17 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes(Array,             
     Object(PHPStan\Analyser\MutatingScope), Object(Closure))                                                                                                                                             
     #18 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(148): PHPStan\Analyser\FileAnalyser->analyseFile('<my-home-dir>/...',    
     Array, Object(PHPStan\Rules\LazyRegistry), Object(PHPStan\Collectors\Registry), NULL)                                                                                                                
     #19 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                     
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)                                                                                                                                      
     #20 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_d3e3292d7\Evenement\EventEmitter->emit('data',  
     Array)                                                                                                                                                                                               
     #21 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                     
     _PHPStan_d3e3292d7\Clue\React\NDJson\Decoder->handleData(Array)                                                                                                                                      
     #22 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_d3e3292d7\Evenement\EventEmitter->emit('data', Array)    
     #23 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                     
     _PHPStan_d3e3292d7\React\Stream\Util::_PHPStan_d3e3292d7\React\Stream\{closure}('{"action":"anal...')                                                                                                
     #24 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154):                                                  
     _PHPStan_d3e3292d7\Evenement\EventEmitter->emit('data', Array)                                                                                                                                       
     #25 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201):                                                  
     _PHPStan_d3e3292d7\React\Stream\DuplexResourceStream->handleData(Resource id #3637)                                                                                                                  
     #26 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173):                                                  
     _PHPStan_d3e3292d7\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)                                                                                                                     
     #27 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(108): _PHPStan_d3e3292d7\React\EventLoop\StreamSelectLoop->run()          
     #28 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):                                                        
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Output\ConsoleOutput))              
     #29 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870):                                                            
     _PHPStan_d3e3292d7\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Input\ArgvInput),                                                              
     Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                           
     #30 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261):                                                            
     _PHPStan_d3e3292d7\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Input\ArgvInput),                  
     Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                           
     #31 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                                            
     _PHPStan_d3e3292d7\Symfony\Component\Console\Application->doRun(Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Input\ArgvInput),                                                                
     Object(_PHPStan_d3e3292d7\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                           
     #32 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_d3e3292d7\Symfony\Component\Console\Application->run()                       
     #33 phar://<my-application-path>/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_d3e3292d7\{closure}()                                                        
     #34 <my-application-path>/vendor/phpstan/phpstan/phpstan(7): require('phar:///<my-home-dir>/...')                                                                                   
     #35 <my-application-path>/vendor/bin/phpstan(112): include('/Users/aphilip/...')                                                                                             
     #36 {main}                                                                                                                                                                                           
     Internal error: Internal error: Return value of PHPStan\Symfony\ConsoleApplicationResolver::getConsoleApplication() must be an instance of Symfony\Component\Console\Application or null, instance   
     of Closure returned in file <my-application-path>/src/Command/MySymfonyCommand.php

The contents of my bin/console is a modified version of the default Symfony console entrypoint : https://github.com/symfony/demo/blob/main/bin/console . Does anyone have any ideas of what might be wrong? Is the returned closure in the default bin/console code an unsupported workflow in phpstan-symfony?

@ondrejmirtes
Copy link
Member

You need to return Application, not Closure. Examples are described in the README: https://github.com/phpstan/phpstan-symfony#analysis-of-symfony-console-commands

@DAcodedBEAT
Copy link
Author

@ondrejmirtes So is the expectation that PHPStan will not be compatible with symfony/runtime going forward?

@ondrejmirtes
Copy link
Member

@DAcodedBEAT It doesn't mean that. It just means that your bin/console file cannot be used as consoleApplicationLoader. You must write a separate script for that.

@DAcodedBEAT
Copy link
Author

Okay, thanks for the clarification!

@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 Mar 18, 2023
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

2 participants