phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
580 stars 96 forks source link

Wrongly usage Doctrine annotation results in PHPStan internal error #353

Open tomtomklima opened 2 years ago

tomtomklima commented 2 years ago

Bug report

Run into PHPStan internal error when tried new feature of Doctrine - use native PHP enum as a entity database value (new in version 2.11 https://www.doctrine-project.org/2022/01/11/orm-2.11.html).

How to reproduce: in annotation for Doctrine entity use wrongly new construct enumType=Status:class - with only one column before class keyword.

Code snippet that reproduces the problem

Do not have https://phpstan.org/try link, but here is the snippet (note single column instead of correct two):

    /**
     * @ORM\Column(type="string", length=32, enumType=Status:class)
     */
    private Status $status;

Expected output

PHPStan should not throw internal error, but correctly catch invalid construct.

Stack trace:
https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:      
     #0                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     AnnotationException.php(80):                                               
     Doctrine\Common\Annotations\AnnotationException::semanticalError('Couldn'  
     t find c...')                                                              
     phpstan/phpstan#1                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1152):                                                       
     Doctrine\Common\Annotations\AnnotationException::semanticalErrorConstants  
     ('OrderStatus:cla...', 'property App\\En...')                              
     phpstan/phpstan#2                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1245): Doctrine\Common\Annotations\DocParser->Constant()     
     phpstan/phpstan#3                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1300): Doctrine\Common\Annotations\DocParser->PlainValue()   
     phpstan/phpstan#4                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1220):                                                       
     Doctrine\Common\Annotations\DocParser->FieldAssignment()                   
     phpstan/phpstan#5                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1063): Doctrine\Common\Annotations\DocParser->Value()        
     phpstan/phpstan#6                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1035): Doctrine\Common\Annotations\DocParser->Values()       
     phpstan/phpstan#7                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(869): Doctrine\Common\Annotations\DocParser->MethodCall()    
     phpstan/phpstan#8                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(719): Doctrine\Common\Annotations\DocParser->Annotation()    
     phpstan/phpstan#9                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(376): Doctrine\Common\Annotations\DocParser->Annotations()   
     phpstan/phpstan#10                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     AnnotationReader.php(178):                                                 
     Doctrine\Common\Annotations\DocParser->parse('/**\n     * @ORM...',        
     'property App\\En...')                                                     
     phpstan/phpstan#11                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     PsrCachedReader.php(155):                                                  
     Doctrine\Common\Annotations\AnnotationReader->getPropertyAnnotations(Obje  
     ct(ReflectionProperty))                                                    
     phpstan/phpstan#12                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     PsrCachedReader.php(88):                                                   
     Doctrine\Common\Annotations\PsrCachedReader->fetchFromCache('App%5CEntity  
     %5C...', Object(ReflectionClass), 'getPropertyAnno...',                    
     Object(ReflectionProperty))                                                
     phpstan/phpstan#13                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     PsrCachedReader.php(98):                                                   
     Doctrine\Common\Annotations\PsrCachedReader->getPropertyAnnotations(Objec  
     t(ReflectionProperty))                                                     
     phpstan/phpstan#14                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/Annotati  
     onDriver.php(357):                                                         
     Doctrine\Common\Annotations\PsrCachedReader->getPropertyAnnotation(Object  
     (ReflectionProperty), 'Doctrine\\ORM\\Ma...')                              
     phpstan/phpstan#15                                                                        
     /application/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/M  
     appingDriverChain.php(77):                                                 
     Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('App\\  
     Entity\\Orde...', Object(Doctrine\ORM\Mapping\ClassMetadata))              
     phpstan/phpstan#16                                                                        
     /application/vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php(45  
     ):                                                                         
     Doctrine\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForCl  
     ass('App\\Entity\\Orde...', Object(Doctrine\ORM\Mapping\ClassMetadata))    
     phpstan/phpstan#17                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFa  
     ctory.php(133):                                                            
     Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver->loadMetadataForClas  
     s('App\\Entity\\Orde...', Object(Doctrine\ORM\Mapping\ClassMetadata))      
     phpstan/phpstan#18                                                                        
     /application/vendor/doctrine/doctrine-bundle/Mapping/ClassMetadataFactory  
     .php(18):                                                                  
     Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine  
     \ORM\Mapping\ClassMetadata), Object(Doctrine\ORM\Mapping\ClassMetadata),   
     false, Array)                                                              
     phpstan/phpstan#19                                                                        
     /application/vendor/doctrine/persistence/src/Persistence/Mapping/Abstract  
     ClassMetadataFactory.php(324):                                             
     Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetada  
     ta(Object(Doctrine\ORM\Mapping\ClassMetadata),                             
     Object(Doctrine\ORM\Mapping\ClassMetadata), false, Array)                  
     phpstan/phpstan#20                                                                        
     /application/vendor/doctrine/persistence/src/Persistence/Mapping/Abstract  
     ClassMetadataFactory.php(192):                                             
     Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('  
     App\\Entity\\Orde...')                                                     
     phpstan/phpstan#21                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(313):  
     Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor  
     ('App\\Entity\\Orde...')                                                   
     phpstan/phpstan#22                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1856):  
     Doctrine\ORM\EntityManager->getClassMetadata('App\\Entity\\Orde...')       
     phpstan/phpstan#23                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1774):  
     Doctrine\ORM\Query\Parser->JoinAssociationDeclaration()                    
     phpstan/phpstan#24                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1668):  
     Doctrine\ORM\Query\Parser->Join()                                          
     phpstan/phpstan#25                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1389):  
     Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration()             
     phpstan/phpstan#26                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(929):   
     Doctrine\ORM\Query\Parser->FromClause()                                    
     phpstan/phpstan#27                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(898):   
     Doctrine\ORM\Query\Parser->SelectStatement()                               
     phpstan/phpstan#28                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(308):   
     Doctrine\ORM\Query\Parser->QueryLanguage()                                 
     phpstan/phpstan#29                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(408):   
     Doctrine\ORM\Query\Parser->getAST()                                        
     phpstan/phpstan#30                                                                        
     /application/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/Quer  
     yResultTypeWalker.php(116): Doctrine\ORM\Query\Parser->parse()             
     phpstan/phpstan#31                                                                        
     /application/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/QueryBuild  
     er/QueryBuilderGetQueryDynamicReturnTypeExtension.php(163):                
     PHPStan\Type\Doctrine\Query\QueryResultTypeWalker::walk(Object(Doctrine\O  
     RM\Query), Object(PHPStan\Type\Doctrine\Query\QueryResultTypeBuilder),     
     Object(PHPStan\Type\Doctrine\DescriptorRegistry))                          
     phpstan/phpstan#32                                                                        
     /application/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/QueryBuild  
     er/QueryBuilderGetQueryDynamicReturnTypeExtension.php(146):                
     PHPStan\Type\Doctrine\QueryBuilder\QueryBuilderGetQueryDynamicReturnTypeE  
     xtension->getQueryType('SELECT ds FROM ...')                               
     phpstan/phpstan#33                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(3468):                                                       
     PHPStan\Type\Doctrine\QueryBuilder\QueryBuilderGetQueryDynamicReturnTypeE  
     xtension->getTypeFromMethodCall(Object(PHPStan\Reflection\ResolvedMethodR  
     eflection), Object(PhpParser\Node\Expr\MethodCall),                        
     Object(PHPStan\Analyser\MutatingScope))                                    
     phpstan/phpstan#34                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1386):                                                       
     PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\  
     Doctrine\QueryBuilder\BranchingQueryBuilderType), 'getQuery',              
     Object(PhpParser\Node\Expr\MethodCall))                                    
     phpstan/phpstan#35                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1392):                                                       
     PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()               
     phpstan/phpstan#36                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(556):                                                        
     PHPStan\Analyser\MutatingScope->resolveType(Object(PhpParser\Node\Expr\Me  
     thodCall))                                                                 
     phpstan/phpstan#37                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1386):                                                       
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\Method  
     Call))                                                                     
     phpstan/phpstan#38                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1392):                                                       
     PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()               
     phpstan/phpstan#39                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(556):                                                        
     PHPStan\Analyser\MutatingScope->resolveType(Object(PhpParser\Node\Expr\Me  
     thodCall))                                                                 
     phpstan/phpstan#40                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Functio  
     nReturnTypeCheck.php(57):                                                  
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\Method  
     Call))                                                                     
     phpstan/phpstan#41                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods  
     /ReturnTypeRule.php(43):                                                   
     PHPStan\Rules\FunctionReturnTypeCheck->checkReturnType(Object(PHPStan\Ana  
     lyser\MutatingScope), Object(PHPStan\Type\UnionType),                      
     Object(PhpParser\Node\Expr\MethodCall),                                    
     Object(PhpParser\Node\Stmt\Return_), 'Method App\\Repo...', 'Method        
     App\\Repo...', 'Method App\\Repo...', 'Method App\\Repo...', false)        
     phpstan/phpstan#42                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/File  
     Analyser.php(105):                                                         
     PHPStan\Rules\Methods\ReturnTypeRule->processNode(Object(PhpParser\Node\S  
     tmt\Return_), Object(PHPStan\Analyser\MutatingScope))                      
     phpstan/phpstan#43                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassSta  
     tementsGatherer.php(95):                                                   
     PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParse  
     r\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope))              
     phpstan/phpstan#44                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(475):                                                    
     PHPStan\Node\ClassStatementsGatherer->__invoke(Object(PhpParser\Node\Stmt  
     \Return_), Object(PHPStan\Analyser\MutatingScope))                         
     phpstan/phpstan#45                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(387):                                                    
     PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}(Object(Php  
     Parser\Node\Stmt\Return_), Object(PHPStan\Analyser\MutatingScope))         
     phpstan/phpstan#46                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(332):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\Return_), Object(PHPStan\Analyser\MutatingScope), Object(Closure))   
     phpstan/phpstan#47                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(490):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Nod  
     e\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope),        
     Object(Closure))                                                           
     phpstan/phpstan#48                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(332):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope),                
     Object(PHPStan\Node\ClassStatementsGatherer))                              
     phpstan/phpstan#49                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(568):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Nod  
     e\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope),             
     Object(PHPStan\Node\ClassStatementsGatherer))                              
     phpstan/phpstan#50                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(332):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure))    
     phpstan/phpstan#51                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(540):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Nod  
     e\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope),         
     Object(Closure))                                                           
     phpstan/phpstan#52                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(302):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope),                 
     Object(Closure))                                                           
     phpstan/phpstan#53                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/File  
     Analyser.php(174):                                                         
     PHPStan\Analyser\NodeScopeResolver->processNodes(Array,                    
     Object(PHPStan\Analyser\MutatingScope), Object(Closure))                   
     phpstan/phpstan#54                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Command/Worke  
     rCommand.php(147):                                                         
     PHPStan\Analyser\FileAnalyser->analyseFile('/application/sr...', Array,    
     Object(PHPStan\Rules\Registry), Object(PHPStan\Collectors\Registry),       
     NULL)                                                                      
     phpstan/phpstan#55                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/  
     evenement/src/Evenement/EventEmitterTrait.php(97):                         
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)            
     phpstan/phpstan#56                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjso  
     n-react/src/Decoder.php(110):                                              
     _PHPStan_4b01b3801\Evenement\EventEmitter->emit('data', Array)             
     phpstan/phpstan#57                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/  
     evenement/src/Evenement/EventEmitterTrait.php(97):                         
     _PHPStan_4b01b3801\Clue\React\NDJson\Decoder->handleData(Array)            
     phpstan/phpstan#58                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stre  
     am/src/Util.php(62):                                                       
     _PHPStan_4b01b3801\Evenement\EventEmitter->emit('data', Array)             
     phpstan/phpstan#59                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/  
     evenement/src/Evenement/EventEmitterTrait.php(97):                         
     _PHPStan_4b01b3801\React\Stream\Util::_PHPStan_4b01b3801\React\Stream\{cl  
     osure}('{"action":"anal...')                                               
     phpstan/phpstan#60                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stre  
     am/src/DuplexResourceStream.php(154):                                      
     _PHPStan_4b01b3801\Evenement\EventEmitter->emit('data', Array)             
     phpstan/phpstan#61                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/even  
     t-loop/src/StreamSelectLoop.php(201):                                      
     _PHPStan_4b01b3801\React\Stream\DuplexResourceStream->handleData(Resource  
     id phpstan/phpstan#3847)                                                                  
     phpstan/phpstan#62                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/even  
     t-loop/src/StreamSelectLoop.php(173):                                      
     _PHPStan_4b01b3801\React\EventLoop\StreamSelectLoop->waitForStreamActivit  
     y(NULL)                                                                    
     phpstan/phpstan#63                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Command/Worke  
     rCommand.php(107):                                                         
     _PHPStan_4b01b3801\React\EventLoop\StreamSelectLoop->run()                 
     phpstan/phpstan#64                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Command/Command.php(259):                                            
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_4b01b3801\Symfony\  
     Component\Console\Input\ArgvInput),                                        
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#65                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Application.php(856):                                                
     _PHPStan_4b01b3801\Symfony\Component\Console\Command\Command->run(Object(  
     _PHPStan_4b01b3801\Symfony\Component\Console\Input\ArgvInput),             
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#66                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Application.php(259):                                                
     _PHPStan_4b01b3801\Symfony\Component\Console\Application->doRunCommand(Ob  
     ject(PHPStan\Command\WorkerCommand),                                       
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Input\ArgvInput),      
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#67                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Application.php(157):                                                
     _PHPStan_4b01b3801\Symfony\Component\Console\Application->doRun(Object(_P  
     HPStan_4b01b3801\Symfony\Component\Console\Input\ArgvInput),               
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#68                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(127):  
     _PHPStan_4b01b3801\Symfony\Component\Console\Application->run()            
     phpstan/phpstan#69                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(128):  
     _PHPStan_4b01b3801\{closure}()                                             
     phpstan/phpstan#70 /application/vendor/phpstan/phpstan/phpstan(8):                        
     require('phar:///applica...')                                              
     phpstan/phpstan#71 /application/vendor/bin/phpstan(117): include('/application/ve...')    
     phpstan/phpstan#72 {main}                                                                 
     Internal error: Internal error: [Semantical Error] Couldn't find constant  
     OrderStatus:class, property App\Entity\Order\Order::$status. in file       
     /application/src/Repository/Order/OrderRepository.php                      

     Post the following stack trace to                                          
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:      
     #0                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     AnnotationException.php(80):                                               
     Doctrine\Common\Annotations\AnnotationException::semanticalError('Couldn'  
     t find c...')                                                              
     phpstan/phpstan#1                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1152):                                                       
     Doctrine\Common\Annotations\AnnotationException::semanticalErrorConstants  
     ('OrderStatus:cla...', 'property App\\En...')                              
     phpstan/phpstan#2                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1245): Doctrine\Common\Annotations\DocParser->Constant()     
     phpstan/phpstan#3                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1300): Doctrine\Common\Annotations\DocParser->PlainValue()   
     phpstan/phpstan#4                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1220):                                                       
     Doctrine\Common\Annotations\DocParser->FieldAssignment()                   
     phpstan/phpstan#5                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1063): Doctrine\Common\Annotations\DocParser->Value()        
     phpstan/phpstan#6                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(1035): Doctrine\Common\Annotations\DocParser->Values()       
     phpstan/phpstan#7                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(869): Doctrine\Common\Annotations\DocParser->MethodCall()    
     phpstan/phpstan#8                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(719): Doctrine\Common\Annotations\DocParser->Annotation()    
     phpstan/phpstan#9                                                                         
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     DocParser.php(376): Doctrine\Common\Annotations\DocParser->Annotations()   
     phpstan/phpstan#10                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     AnnotationReader.php(178):                                                 
     Doctrine\Common\Annotations\DocParser->parse('/**\n     * @ORM...',        
     'property App\\En...')                                                     
     phpstan/phpstan#11                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     PsrCachedReader.php(155):                                                  
     Doctrine\Common\Annotations\AnnotationReader->getPropertyAnnotations(Obje  
     ct(ReflectionProperty))                                                    
     phpstan/phpstan#12                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     PsrCachedReader.php(88):                                                   
     Doctrine\Common\Annotations\PsrCachedReader->fetchFromCache('App%5CEntity  
     %5C...', Object(ReflectionClass), 'getPropertyAnno...',                    
     Object(ReflectionProperty))                                                
     phpstan/phpstan#13                                                                        
     /application/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/  
     PsrCachedReader.php(98):                                                   
     Doctrine\Common\Annotations\PsrCachedReader->getPropertyAnnotations(Objec  
     t(ReflectionProperty))                                                     
     phpstan/phpstan#14                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/Annotati  
     onDriver.php(357):                                                         
     Doctrine\Common\Annotations\PsrCachedReader->getPropertyAnnotation(Object  
     (ReflectionProperty), 'Doctrine\\ORM\\Ma...')                              
     phpstan/phpstan#15                                                                        
     /application/vendor/doctrine/persistence/src/Persistence/Mapping/Driver/M  
     appingDriverChain.php(77):                                                 
     Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('App\\  
     Entity\\Orde...', Object(Doctrine\ORM\Mapping\ClassMetadata))              
     phpstan/phpstan#16                                                                        
     /application/vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php(45  
     ):                                                                         
     Doctrine\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForCl  
     ass('App\\Entity\\Orde...', Object(Doctrine\ORM\Mapping\ClassMetadata))    
     phpstan/phpstan#17                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFa  
     ctory.php(133):                                                            
     Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver->loadMetadataForClas  
     s('App\\Entity\\Orde...', Object(Doctrine\ORM\Mapping\ClassMetadata))      
     phpstan/phpstan#18                                                                        
     /application/vendor/doctrine/doctrine-bundle/Mapping/ClassMetadataFactory  
     .php(18):                                                                  
     Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine  
     \ORM\Mapping\ClassMetadata), Object(Doctrine\ORM\Mapping\ClassMetadata),   
     false, Array)                                                              
     phpstan/phpstan#19                                                                        
     /application/vendor/doctrine/persistence/src/Persistence/Mapping/Abstract  
     ClassMetadataFactory.php(324):                                             
     Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetada  
     ta(Object(Doctrine\ORM\Mapping\ClassMetadata),                             
     Object(Doctrine\ORM\Mapping\ClassMetadata), false, Array)                  
     phpstan/phpstan#20                                                                        
     /application/vendor/doctrine/persistence/src/Persistence/Mapping/Abstract  
     ClassMetadataFactory.php(192):                                             
     Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('  
     App\\Entity\\Orde...')                                                     
     phpstan/phpstan#21                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(313):  
     Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor  
     ('App\\Entity\\Orde...')                                                   
     phpstan/phpstan#22                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1817):  
     Doctrine\ORM\EntityManager->getClassMetadata('App\\Entity\\Orde...')       
     phpstan/phpstan#23                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1656):  
     Doctrine\ORM\Query\Parser->RangeVariableDeclaration()                      
     phpstan/phpstan#24                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1389):  
     Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration()             
     phpstan/phpstan#25                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(929):   
     Doctrine\ORM\Query\Parser->FromClause()                                    
     phpstan/phpstan#26                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(898):   
     Doctrine\ORM\Query\Parser->SelectStatement()                               
     phpstan/phpstan#27                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(308):   
     Doctrine\ORM\Query\Parser->QueryLanguage()                                 
     phpstan/phpstan#28                                                                        
     /application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(408):   
     Doctrine\ORM\Query\Parser->getAST()                                        
     phpstan/phpstan#29                                                                        
     /application/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/Quer  
     yResultTypeWalker.php(116): Doctrine\ORM\Query\Parser->parse()             
     phpstan/phpstan#30                                                                        
     /application/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/QueryBuild  
     er/QueryBuilderGetQueryDynamicReturnTypeExtension.php(163):                
     PHPStan\Type\Doctrine\Query\QueryResultTypeWalker::walk(Object(Doctrine\O  
     RM\Query), Object(PHPStan\Type\Doctrine\Query\QueryResultTypeBuilder),     
     Object(PHPStan\Type\Doctrine\DescriptorRegistry))                          
     phpstan/phpstan#31                                                                        
     /application/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/QueryBuild  
     er/QueryBuilderGetQueryDynamicReturnTypeExtension.php(146):                
     PHPStan\Type\Doctrine\QueryBuilder\QueryBuilderGetQueryDynamicReturnTypeE  
     xtension->getQueryType('SELECT o FROM A...')                               
     phpstan/phpstan#32                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(3468):                                                       
     PHPStan\Type\Doctrine\QueryBuilder\QueryBuilderGetQueryDynamicReturnTypeE  
     xtension->getTypeFromMethodCall(Object(PHPStan\Reflection\ResolvedMethodR  
     eflection), Object(PhpParser\Node\Expr\MethodCall),                        
     Object(PHPStan\Analyser\MutatingScope))                                    
     phpstan/phpstan#33                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1386):                                                       
     PHPStan\Analyser\MutatingScope->methodCallReturnType(Object(PHPStan\Type\  
     Doctrine\QueryBuilder\BranchingQueryBuilderType), 'getQuery',              
     Object(PhpParser\Node\Expr\MethodCall))                                    
     phpstan/phpstan#34                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1392):                                                       
     PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()               
     phpstan/phpstan#35                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(556):                                                        
     PHPStan\Analyser\MutatingScope->resolveType(Object(PhpParser\Node\Expr\Me  
     thodCall))                                                                 
     phpstan/phpstan#36                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1386):                                                       
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\Method  
     Call))                                                                     
     phpstan/phpstan#37                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(1392):                                                       
     PHPStan\Analyser\MutatingScope->PHPStan\Analyser\{closure}()               
     phpstan/phpstan#38                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Muta  
     tingScope.php(556):                                                        
     PHPStan\Analyser\MutatingScope->resolveType(Object(PhpParser\Node\Expr\Me  
     thodCall))                                                                 
     phpstan/phpstan#39                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(1422):                                                   
     PHPStan\Analyser\MutatingScope->getType(Object(PhpParser\Node\Expr\Method  
     Call))                                                                     
     phpstan/phpstan#40                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(2635):                                                   
     PHPStan\Analyser\NodeScopeResolver->PHPStan\Analyser\{closure}(Object(PHP  
     Stan\Analyser\MutatingScope))                                              
     phpstan/phpstan#41                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(1432):                                                   
     PHPStan\Analyser\NodeScopeResolver->processAssignVar(Object(PHPStan\Analy  
     ser\MutatingScope), Object(PhpParser\Node\Expr\Variable),                  
     Object(PhpParser\Node\Expr\MethodCall), Object(Closure),                   
     Object(PHPStan\Analyser\ExpressionContext), Object(Closure), true)         
     phpstan/phpstan#42                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(527):                                                    
     PHPStan\Analyser\NodeScopeResolver->processExprNode(Object(PhpParser\Node  
     \Expr\Assign), Object(PHPStan\Analyser\MutatingScope), Object(Closure),    
     Object(PHPStan\Analyser\ExpressionContext))                                
     phpstan/phpstan#43                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(332):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\Expression), Object(PHPStan\Analyser\MutatingScope),                 
     Object(Closure))                                                           
     phpstan/phpstan#44                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(490):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Nod  
     e\Stmt\ClassMethod), Array, Object(PHPStan\Analyser\MutatingScope),        
     Object(Closure))                                                           
     phpstan/phpstan#45                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(332):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\ClassMethod), Object(PHPStan\Analyser\MutatingScope),                
     Object(PHPStan\Node\ClassStatementsGatherer))                              
     phpstan/phpstan#46                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(568):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Nod  
     e\Stmt\Class_), Array, Object(PHPStan\Analyser\MutatingScope),             
     Object(PHPStan\Node\ClassStatementsGatherer))                              
     phpstan/phpstan#47                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(332):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure))    
     phpstan/phpstan#48                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(540):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Nod  
     e\Stmt\Namespace_), Array, Object(PHPStan\Analyser\MutatingScope),         
     Object(Closure))                                                           
     phpstan/phpstan#49                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Node  
     ScopeResolver.php(302):                                                    
     PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node  
     \Stmt\Namespace_), Object(PHPStan\Analyser\MutatingScope),                 
     Object(Closure))                                                           
     phpstan/phpstan#50                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/File  
     Analyser.php(174):                                                         
     PHPStan\Analyser\NodeScopeResolver->processNodes(Array,                    
     Object(PHPStan\Analyser\MutatingScope), Object(Closure))                   
     phpstan/phpstan#51                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Command/Worke  
     rCommand.php(147):                                                         
     PHPStan\Analyser\FileAnalyser->analyseFile('/application/sr...', Array,    
     Object(PHPStan\Rules\Registry), Object(PHPStan\Collectors\Registry),       
     NULL)                                                                      
     phpstan/phpstan#52                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/  
     evenement/src/Evenement/EventEmitterTrait.php(97):                         
     PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)            
     phpstan/phpstan#53                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjso  
     n-react/src/Decoder.php(110):                                              
     _PHPStan_4b01b3801\Evenement\EventEmitter->emit('data', Array)             
     phpstan/phpstan#54                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/  
     evenement/src/Evenement/EventEmitterTrait.php(97):                         
     _PHPStan_4b01b3801\Clue\React\NDJson\Decoder->handleData(Array)            
     phpstan/phpstan#55                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stre  
     am/src/Util.php(62):                                                       
     _PHPStan_4b01b3801\Evenement\EventEmitter->emit('data', Array)             
     phpstan/phpstan#56                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/  
     evenement/src/Evenement/EventEmitterTrait.php(97):                         
     _PHPStan_4b01b3801\React\Stream\Util::_PHPStan_4b01b3801\React\Stream\{cl  
     osure}('{"action":"anal...')                                               
     phpstan/phpstan#57                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stre  
     am/src/DuplexResourceStream.php(154):                                      
     _PHPStan_4b01b3801\Evenement\EventEmitter->emit('data', Array)             
     phpstan/phpstan#58                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/even  
     t-loop/src/StreamSelectLoop.php(201):                                      
     _PHPStan_4b01b3801\React\Stream\DuplexResourceStream->handleData(Resource  
     id phpstan/phpstan#3847)                                                                  
     phpstan/phpstan#59                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/react/even  
     t-loop/src/StreamSelectLoop.php(173):                                      
     _PHPStan_4b01b3801\React\EventLoop\StreamSelectLoop->waitForStreamActivit  
     y(NULL)                                                                    
     phpstan/phpstan#60                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/src/Command/Worke  
     rCommand.php(107):                                                         
     _PHPStan_4b01b3801\React\EventLoop\StreamSelectLoop->run()                 
     phpstan/phpstan#61                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Command/Command.php(259):                                            
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_4b01b3801\Symfony\  
     Component\Console\Input\ArgvInput),                                        
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#62                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Application.php(856):                                                
     _PHPStan_4b01b3801\Symfony\Component\Console\Command\Command->run(Object(  
     _PHPStan_4b01b3801\Symfony\Component\Console\Input\ArgvInput),             
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#63                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Application.php(259):                                                
     _PHPStan_4b01b3801\Symfony\Component\Console\Application->doRunCommand(Ob  
     ject(PHPStan\Command\WorkerCommand),                                       
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Input\ArgvInput),      
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#64                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/co  
     nsole/Application.php(157):                                                
     _PHPStan_4b01b3801\Symfony\Component\Console\Application->doRun(Object(_P  
     HPStan_4b01b3801\Symfony\Component\Console\Input\ArgvInput),               
     Object(_PHPStan_4b01b3801\Symfony\Component\Console\Output\ConsoleOutput)  
     )                                                                          
     phpstan/phpstan#65                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(127):  
     _PHPStan_4b01b3801\Symfony\Component\Console\Application->run()            
     phpstan/phpstan#66                                                                        
     phar:///application/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(128):  
     _PHPStan_4b01b3801\{closure}()                                             
     phpstan/phpstan#67 /application/vendor/phpstan/phpstan/phpstan(8):                        
     require('phar:///applica...')                                              
     phpstan/phpstan#68 /application/vendor/bin/phpstan(117): include('/application/ve...')    
     phpstan/phpstan#69 {main}                                                                 
     Child process error (exit code 1):                                         
     Child process error (exit code 1): 
mergeable[bot] commented 2 years ago

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

It will most likely be closed after manual review.

stof commented 1 week ago

If the annotation parser fails at parsing annotation, getting the metadata with the object manager will fail.

@ondrejmirtes solving this issue would be about changing the way phpstan-doctrine behaves when Doctrine reports an error during the loading of metadata (note that it has nothing to do with enums specifically, as the same could happen with another kind of invalid annotations)