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

Disable result set type-inference and other rules #745

Open
faizanakram99 opened this issue Feb 18, 2025 · 4 comments
Open

Disable result set type-inference and other rules #745

faizanakram99 opened this issue Feb 18, 2025 · 4 comments

Comments

@faizanakram99
Copy link

Hi, we're using phpstan with level 8 and want to use this plugin for just SQL errors and nothing else. It is crashing things unnecessarily otherwise. Sometimes with one file, and sometimes with some other file.

Is it possible?

See this crash for example.

 ## /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/DbSchema/SchemaHasherMysql.php(91)                                                                                                                                  
     #0 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/QueryReflection/ReplayAndRecordingQueryReflector.php(37): staabm\PHPStanDba\DbSchema\SchemaHasherMysql->hashDb()                                                    
     #1 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/QueryReflection/ReplayAndRecordingQueryReflector.php(69): staabm\PHPStanDba\QueryReflection\ReplayAndRecordingQueryReflector->dbSchemaChanged()                     
     #2 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/QueryReflection/ChainedReflector.php(55): staabm\PHPStanDba\QueryReflection\ReplayAndRecordingQueryReflector->getResultType()                                       
     #3 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/QueryReflection/QueryReflection.php(110): staabm\PHPStanDba\QueryReflection\ChainedReflector->getResultType()                                                       
     #4 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/DoctrineReflection/DoctrineReflection.php(230): staabm\PHPStanDba\QueryReflection\QueryReflection->getResultType()                                                  
     #5 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/Extensions/DoctrineConnectionFetchDynamicReturnTypeExtension.php(90): staabm\PHPStanDba\DoctrineReflection\DoctrineReflection->createFetchType()                    
     #6 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/staabm/phpstan-dba/src/Extensions/DoctrineConnectionFetchDynamicReturnTypeExtension.php(70): staabm\PHPStanDba\Extensions\DoctrineConnectionFetchDynamicReturnTypeExtension->inferType()   
     #7 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(3888): staabm\PHPStanDba\Extensions\DoctrineConnectionFetchDynamicReturnTypeExtension->getTypeFromMethodCall()          
     #8 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1499): PHPStan\Analyser\MutatingScope->methodCallReturnType()                                                           
     #9 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1505): PHPStan\Analyser\MutatingScope->{closure:PHPStan\Analyser\MutatingScope::resolveType():1498}()                   
     #10 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(554): PHPStan\Analyser\MutatingScope->resolveType()                                                                    
     #11 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(1368): PHPStan\Analyser\MutatingScope->getType()                                                                       
     #12 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/MutatingScope.php(554): PHPStan\Analyser\MutatingScope->resolveType()                                                                    
     #13 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Rules/FunctionReturnTypeCheck.php(49): PHPStan\Analyser\MutatingScope->getType()                                                                  
     #14 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Rules/Methods/ReturnTypeRule.php(58): PHPStan\Rules\FunctionReturnTypeCheck->checkReturnType()                                                    
     #15 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(103): PHPStan\Rules\Methods\ReturnTypeRule->processNode()                                                               
     #16 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(116): PHPStan\Analyser\FileAnalyser->{closure:PHPStan\Analyser\FileAnalyser::analyseFile():83}()                 
     #17 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(654): PHPStan\Node\ClassStatementsGatherer->__invoke()                                                             
     #18 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(526): PHPStan\Analyser\NodeScopeResolver::{closure:PHPStan\Analyser\NodeScopeResolver::processStmtNode():653}()    
     #19 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(456): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                        
     #20 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(653): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                       
     #21 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(456): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                        
     #22 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(793): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                       
     #23 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(456): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                        
     #24 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(760): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()                                                       
     #25 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(404): PHPStan\Analyser\NodeScopeResolver->processStmtNode()                                                        
     #26 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(162): PHPStan\Analyser\NodeScopeResolver->processNodes()                                                                
     #27 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(136): PHPStan\Analyser\FileAnalyser->analyseFile()                                                                      
     #28 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): PHPStan\Command\WorkerCommand::{closure:PHPStan\Command\WorkerCommand::runWorker():117}()  
     #29 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_e140197a0\Evenement\EventEmitter->emit()                                                      
     #30 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111): _PHPStan_e140197a0\Clue\React\NDJson\Decoder->handleData()                                 
     #31 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_e140197a0\Evenement\EventEmitter->emit()                                                               
     #32 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/EventEmitterTrait.php(111):                                                                                            
     _PHPStan_e140197a0\React\Stream\Util::{closure:_PHPStan_e140197a0\React\Stream\Util::forwardEvents():61}()                                                                                                                                                   
     #33 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(168): _PHPStan_e140197a0\Evenement\EventEmitter->emit()                                              
     #34 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_e140197a0\React\Stream\DuplexResourceStream->handleData()                             
     #35 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_e140197a0\React\EventLoop\StreamSelectLoop->waitForStreamActivity()                   
     #36 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(96): _PHPStan_e140197a0\React\EventLoop\StreamSelectLoop->run()                                                         
     #37 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\WorkerCommand->execute()                                                             
     #38 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870): _PHPStan_e140197a0\Symfony\Component\Console\Command\Command->run()                                      
     #39 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261): _PHPStan_e140197a0\Symfony\Component\Console\Application->doRunCommand()                                 
     #40 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_e140197a0\Symfony\Component\Console\Application->doRun()                                        
     #41 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(114): _PHPStan_e140197a0\Symfony\Component\Console\Application->run()                                                                     
     #42 phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(115): {closure:phar:///home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan:14}()       
     #43 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/phpstan/phpstan/phpstan(8): require('...')                                                                                                                                                
     #44 /home/ubuntu/Repositories/qbil-trade/vendor-bin/phpstan/vendor/bin/phpstan(119): include('...')                                                                                                                                                          
     #45 {main}                                                                                                                                                                                                                                                   
 -- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
@staabm
Copy link
Owner

staabm commented Feb 18, 2025

Hi. Could you create a reproducer for the crash?

Which php version, which dbal driver?

@faizanakram99
Copy link
Author

Hi. Could you create a reproducer for the crash?

Which php version, which dbal driver?

PHP 8.4, mysqli driver.

I can't create a reproducer, that's the whole point. It crashes randomly.

I only want to use this plugin for checking errors like missing table, etc.

@staabm
Copy link
Owner

staabm commented Feb 18, 2025

I guess you could make your case easier to reproduce when invoking PHPStan with -v --debug.

I think when we disable all features but syntax checking it will not stop crashing.

We should try to address the root problem

@staabm
Copy link
Owner

staabm commented Feb 19, 2025

looking more closely at the stacktrace of your error it seems you are using ReplayAndRecordingQueryReflector in combination with SchemaHasherMysql.

you could just use MysqliQueryReflector without wrapping it into ReplayAndRecordingQueryReflector - this might fix the exception as no SchemaHasher is required when not using ReplayAndRecordingQueryReflector:

<?php // phpstan-dba.php config file
// ..
QueryReflection::setupReflector(
    new MysqliQueryReflector($mysqli),
    $config
);

(or you can attach a debugger onto SchemaHasherMysql and check why it returns a empty string in your case)

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

No branches or pull requests

2 participants