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

Missing Interface class #281

Closed
norgeindian opened this issue Dec 20, 2022 · 9 comments · Fixed by #284
Closed

Missing Interface class #281

norgeindian opened this issue Dec 20, 2022 · 9 comments · Fixed by #284

Comments

@norgeindian
Copy link

When running phpstan in the newest version, I get the following error:

 Internal error: Internal error: Magento\MediaStorage\Model\File\Validator\NotProtectedInterface does not exist and has no extension interface in file                                                             
     /var/www/html/src/XXX/YYY/Service/SaveOrderAttachmentService.php                                                                                                                                         
                                                                                                                                                                                                                       
     Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md:                                                                                                           
     #0 /var/www/html/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionInterfaceAutoloader.php(69):                                                                                    
     bitExpert\PHPStan\Magento\Autoload\ExtensionInterfaceAutoloader->getFileContents('Magento\\MediaSt...')                                                                                                           
     #1 [internal function]: bitExpert\PHPStan\Magento\Autoload\ExtensionInterfaceAutoloader->autoload('Magento\\MediaSt...')                                                                                          
     #2 /tmp/phpstan/cache/PHPStan/7d/6b/7d6bd484079da112a565e263fa30749650fde76b.php(5): spl_autoload_call('Magento\\MediaSt...')                                                                                     
     #3 /var/www/html/vendor/bitexpert/phpstan-magento/src/bitExpert/PHPStan/Magento/Autoload/ExtensionAutoloader.php(66): require_once('/tmp/phpstan/ca...')                                                          
     #4 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/SourceLocator/AutoloadFunctionsSourceLocator.php(41):                                                                 
     bitExpert\PHPStan\Magento\Autoload\ExtensionAutoloader->autoload('Magento\\MediaSt...')                                                                                                                           
     #5 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/ondrejmirtes/better-reflection/src/SourceLocator/Type/AggregateSourceLocator.php(26):                                                          
     PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadFunctionsSourceLocator->locateIdentifier(Object(PHPStan\BetterReflection\Reflector\DefaultReflector),                                                   
     Object(PHPStan\BetterReflection\Identifier\Identifier))                                                                                                                                                           
     #6 phar:///var/www/html/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))         
     #7 phar:///var/www/html/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))         
     #8 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/Reflector/MemoizingReflector.php(45):                                                                                 
     PHPStan\BetterReflection\Reflector\DefaultReflector->reflectClass('Magento\\MediaSt...')                                                                                                                          
     #9 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/BetterReflection/BetterReflectionProvider.php(149):                                                                                    
     PHPStan\Reflection\BetterReflection\Reflector\MemoizingReflector->reflectClass('Magento\\MediaSt...')                                                                                                             
     #10 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Reflection/ReflectionProvider/MemoizingReflectionProvider.php(35):                                                                               
     PHPStan\Reflection\BetterReflection\BetterReflectionProvider->hasClass('Magento\\MediaSt...')                                                                                                                     
     #11 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Rules/ClassCaseSensitivityCheck.php(34): PHPStan\Reflection\ReflectionProvider\MemoizingReflectionProvider->hasClass('Magento\\MediaSt...')      
     #12 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Namespaces/ExistingNamesInUseRule.php(107): PHPStan\Rules\ClassCaseSensitivityCheck->checkClassNames(Array)                                
     #13 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Namespaces/ExistingNamesInUseRule.php(61): PHPStan\Rules\Namespaces\ExistingNamesInUseRule->checkClasses(Array)                            
     #14 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(106): PHPStan\Rules\Namespaces\ExistingNamesInUseRule->processNode(Object(PhpParser\Node\Stmt\Use_),                   
     Object(PHPStan\Analyser\MutatingScope))                                                                                                                                                                           
     #15 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(415): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PhpParser\Node\Stmt\Use_),                 
     Object(PHPStan\Analyser\MutatingScope))                                                                                                                                                                           
     #16 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(360): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Use_),                       
     Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))                                                                                                               
     #17 phar:///var/www/html/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))                                                                                                               
     #18 phar:///var/www/html/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))                                                                                                               
     #19 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(175): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope),                  
     Object(Closure))                                                                                                                                                                                                  
     #20 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(147): PHPStan\Analyser\FileAnalyser->analyseFile('/var/www/html/s...', Array, Object(PHPStan\Rules\LazyRegistry),      
     Object(PHPStan\Collectors\Registry), NULL)                                                                                                                                                                        
     #21 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)                  
     #22 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(110): _PHPStan_0f7d3d695\Evenement\EventEmitter->emit('data', Array)                                        
     #23 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_0f7d3d695\Clue\React\NDJson\Decoder->handleData(Array)                  
     #24 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_0f7d3d695\Evenement\EventEmitter->emit('data', Array)                                                 
     #25 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):                                                                                  
     _PHPStan_0f7d3d695\React\Stream\Util::_PHPStan_0f7d3d695\React\Stream\{closure}('{"action":"anal...')                                                                                                             
     #26 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_0f7d3d695\Evenement\EventEmitter->emit('data', Array)                                
     #27 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_0f7d3d695\React\Stream\DuplexResourceStream->handleData(Resource id #8300)           
     #28 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_0f7d3d695\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)              
     #29 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(107): _PHPStan_0f7d3d695\React\EventLoop\StreamSelectLoop->run()                                                       
     #30 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):                                                                                                     
     PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Output\ConsoleOutput))                           
     #31 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(868):                                                                                                         
     _PHPStan_0f7d3d695\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Input\ArgvInput),                                                                           
     Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                        
     #32 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259):                                                                                                         
     _PHPStan_0f7d3d695\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Input\ArgvInput),                               
     Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Output\ConsoleOutput))                                                                                                                                        
     #33 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):                                                                                                         
     _PHPStan_0f7d3d695\Symfony\Component\Console\Application->doRun(Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_0f7d3d695\Symfony\Component\Console\Output\ConsoleOutput))  
     #34 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_0f7d3d695\Symfony\Component\Console\Application->run()                                                                    
     #35 phar:///var/www/html/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_0f7d3d695\{closure}()                                                                                                     
     #36 /var/www/html/vendor/phpstan/phpstan/phpstan(7): require('phar:///var/www...')                                                                                                                                
     #37 /var/www/html/vendor/bin/phpstan(115): include('/var/www/html/v...')                                                                                                                                          
     #38 {main}                                                                                                                                                                                                        
     Child process error (exit code 1):             

In the mentioned class I only have a dependency on Magento\MediaStorage\Model\File\Validator\NotProtectedExtension, which definitely exists. Don't really understand how he then goes to Magento\MediaStorage\Model\File\Validator\NotProtectedInterface.
Might it be, that there is something wrong with the autoloader here?
I'm using 'bitexpert/phpstan-magento' in version v0.27.0and phpstan/phpstan in version 1.9.3 on Magento 2.4.5-p1.

@shochdoerfer
Copy link
Member

Thanks for opening your first issue in this repo :)

Apparently, this is a side-effect of the extension attribute autoloader we have implemented. Since the class name ends with "Extension" the autoloader tries to generate an extension class from it.

Let me check what we can do about it. I am thinking of adding the same check as for the factories. If a class by that name already exists locally or in vendor, skip the whole autoloader to generate the extension class files.

@norgeindian
Copy link
Author

@shochdoerfer, ah, okay, I understand. That could be the reason, indeed. Already wondered why he tries to look for an interface here.
Cool, would be awesome, if you could find a way to make that work somehow.
Please let me know, if I can be of any help.

@shochdoerfer
Copy link
Member

@norgeindian this is the check that needs to be added to both the ExtensionAutoloader and the ExtensionInterfaceAutoloader https://github.com/bitExpert/phpstan-magento/blob/master/src/bitExpert/PHPStan/Magento/Autoload/FactoryAutoloader.php#L47

The dependency needs to be added to the constructor and configured in the extension.neon file.

@makao
Copy link

makao commented Jan 16, 2023

@shochdoerfer it seems to be an issue also when using alongside with https://github.com/phpstan/phpstan-phpunit, because https://github.com/phpstan/phpstan-phpunit/search?q=Extension

Issue occurs only when there is a result cache, running with cache disabled (--debug flag) works fine.

@shochdoerfer
Copy link
Member

@makao Good catch. Apparently, I did not have that extension installed in my Magento projects. I wonder why?

@shochdoerfer
Copy link
Member

@norgeindian @makao could you people please check if the dev-master version works as expected?

@makao
Copy link

makao commented Jan 21, 2023

@shochdoerfer works like a charm, thanks.

@shochdoerfer
Copy link
Member

Published 0.28.0 with this issue being fixed.

@norgeindian
Copy link
Author

@shochdoerfer, sorry, that I opened that I opened that issue and then never replied again. We had a big launch last week, and so I did not find time for the project anymore, where this issue happened.
But included the update now, and it works perfectly, thanks a lot for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants