Skip to content

Compatibility with doctrine/orm:3 #529

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
W0rma opened this issue Feb 5, 2024 · 9 comments
Closed

Compatibility with doctrine/orm:3 #529

W0rma opened this issue Feb 5, 2024 · 9 comments

Comments

@W0rma
Copy link

W0rma commented Feb 5, 2024

doctrine/orm:3.0 was released a few days ago: https://github.com/doctrine/orm/releases/tag/3.0.0

I get the following error when using v3:

PHP Fatal error:  Declaration of PHPStan\Type\Doctrine\Query\QueryResultTypeWalker::walkSelectStatement(Doctrine\ORM\Query\AST\SelectStatement $AST) must be  
     compatible with Doctrine\ORM\Query\SqlWalker::walkSelectStatement(Doctrine\ORM\Query\AST\SelectStatement $selectStatement): string in                                                              
     /var/www/html/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/QueryResultTypeWalker.php on line 175                                                                                        
     Fatal error: Declaration of PHPStan\Type\Doctrine\Query\QueryResultTypeWalker::walkSelectStatement(Doctrine\ORM\Query\AST\SelectStatement $AST) must be compatible with                            
     Doctrine\ORM\Query\SqlWalker::walkSelectStatement(Doctrine\ORM\Query\AST\SelectStatement $selectStatement): string in                                                                              
     /var/www/html/vendor/phpstan/phpstan-doctrine/src/Type/Doctrine/Query/QueryResultTypeWalker.php on line 175
@W0rma
Copy link
Author

W0rma commented Feb 5, 2024

Are there any plans to drop older PHP versions?

https://github.com/doctrine/orm/blob/3.0.x/src/Query/SqlWalker.php uses union types which are not available in PHP 7.x.
However, phpstan/phpstan-doctrine does still support PHP 7.2

@VincentLanglet
Copy link
Contributor

Currently ORM v3 is not supported, I took a look and it's not an easy task (#531) but I'm not sure we need to drop old php version support.

@ondrejmirtes
Copy link
Member

Hello, phpstan-doctrine is not yet fully compatible and verified to work with Doctrine ORM 3.0 and DBAL 4.0, but I did some work to make forward-compatible changes that should work both with old and new versions: 9534fcd...30cf38d

These changes have just been released in phpstan-doctrine 1.3.60: https://github.com/phpstan/phpstan-doctrine/releases/tag/1.3.60 Please report back how they work for you, thanks.

The work on full compatibility with Doctrine ORM 3.0 and DBAL 4.0 continues in #535.

@knallcharge
Copy link

Using v1.3.60 with orm v3 results in the following error:

Internal error: Internal error: array_key_exists(): Argument #2 ($array) must be of type array, Doctrine\ORM\Mapping\FieldMapping given while analysing file (...)\src\Entity\User.php

 Post the following stack trace to https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml:
 ## (...)\vendor\phpstan\phpstan-doctrine\src\Rules\Doctrine\ORM\PropertiesExtension.php(50)
 #0 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Rules/DeadCode/UnusedPrivatePropertyRule.php(103):
 PHPStan\Rules\Doctrine\ORM\PropertiesExtension->isAlwaysWritten(Object(PHPStan\Reflection\Php\PhpPropertyReflection), 'id')
 #1 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(107): PHPStan\Rules\DeadCode\UnusedPrivatePropertyRule->processNode(Object(PHPStan\Node\ClassPropertiesNode),
 Object(PHPStan\Analyser\MutatingScope))
 #2 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(669): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PHPStan\Node\ClassPropertiesNode),
 Object(PHPStan\Analyser\MutatingScope))
 #3 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(401): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_),
 Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
 #4 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(640): PHPStan\Analyser\NodeScopeResolver->processStmtNodes(Object(PhpParser\Node\Stmt\Namespace_), Array,
 Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
 #5 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(370): PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Namespace_),
 Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))
 #6 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(166): PHPStan\Analyser\NodeScopeResolver->processNodes(Array, Object(PHPStan\Analyser\MutatingScope), Object(Closure))
 #7 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(132): PHPStan\Analyser\FileAnalyser->analyseFile('C:\\xampp\\htdocs...', Array, Object(PHPStan\Rules\LazyRegistry),
 Object(PHPStan\Collectors\Registry), NULL)
 #8 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): PHPStan\Command\WorkerCommand->PHPStan\Command\{closure}(Array)
 #9 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/clue/ndjson-react/src/Decoder.php(117): _PHPStan_11268e5ee\Evenement\EventEmitter->emit('data', Array)
 #10 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97): _PHPStan_11268e5ee\Clue\React\NDJson\Decoder->handleData(Array)
 #11 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/Util.php(62): _PHPStan_11268e5ee\Evenement\EventEmitter->emit('data', Array)
 #12 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(97):
 _PHPStan_11268e5ee\React\Stream\Util::_PHPStan_11268e5ee\React\Stream\{closure}('{"action":"anal...')
 #13 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/react/stream/src/DuplexResourceStream.php(154): _PHPStan_11268e5ee\Evenement\EventEmitter->emit('data', Array)
 #14 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(201): _PHPStan_11268e5ee\React\Stream\DuplexResourceStream->handleData(Resource id #5736)
 #15 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/react/event-loop/src/StreamSelectLoop.php(173): _PHPStan_11268e5ee\React\EventLoop\StreamSelectLoop->waitForStreamActivity(NULL)
 #16 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/src/Command/WorkerCommand.php(98): _PHPStan_11268e5ee\React\EventLoop\StreamSelectLoop->run()
 #17 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259):
 PHPStan\Command\WorkerCommand->execute(Object(_PHPStan_11268e5ee\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_11268e5ee\Symfony\Component\Console\Output\ConsoleOutput))
 #18 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(870):
 _PHPStan_11268e5ee\Symfony\Component\Console\Command\Command->run(Object(_PHPStan_11268e5ee\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_11268e5ee\Symfony\Component\Console\Output\ConsoleOutput))
 #19 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(261):
 _PHPStan_11268e5ee\Symfony\Component\Console\Application->doRunCommand(Object(PHPStan\Command\WorkerCommand), Object(_PHPStan_11268e5ee\Symfony\Component\Console\Input\ArgvInput),
 Object(_PHPStan_11268e5ee\Symfony\Component\Console\Output\ConsoleOutput))
 #20 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157):
 _PHPStan_11268e5ee\Symfony\Component\Console\Application->doRun(Object(_PHPStan_11268e5ee\Symfony\Component\Console\Input\ArgvInput), Object(_PHPStan_11268e5ee\Symfony\Component\Console\Output\ConsoleOutput))
 #21 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(124): _PHPStan_11268e5ee\Symfony\Component\Console\Application->run()
 #22 phar://(...)/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(125): _PHPStan_11268e5ee\{closure}()
 #23 (...)\vendor\phpstan\phpstan\phpstan(8): require('phar://C:/xampp...')
 #24 (...)\vendor\bin\phpstan(119): include('C:\\xampp\\htdocs...')
 #25 {main}
 Child process error (exit code 1)

@eliashaeussler
Copy link

@knallcharge This should be fixed by #537.

@lugosium
Copy link

lugosium commented Feb 8, 2024

Hello,

Thanks for your work, with the new release, i got:

Internal error: Internal error: array_key_exists(): Argument #2 ($array) must be of type array, Doctrine\ORM\Mapping\FieldMapping given while analysing file
     SomeFile.php

## project_root/vendor/phpstan/phpstan-doctrine/src/Rules/Doctrine/ORM/PropertiesExtension.php(50)
#0 phar://project_root/vendor/phpstan/phpstan/phpstan.phar/src/Rules/DeadCode/UnusedPrivatePropertyRule.php(103):
PHPStan\Rules\Doctrine\ORM\PropertiesExtension->isAlwaysWritten(Object(PHPStan\Reflection\Php\PhpPropertyReflection), 'id')

#1 phar://project_root/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(107):
PHPStan\Rules\DeadCode\UnusedPrivatePropertyRule->processNode(Object(PHPStan\Node\ClassPropertiesNode), Object(PHPStan\Analyser\MutatingScope))
#2 phar://project_root/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(669):
PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}(Object(PHPStan\Node\ClassPropertiesNode), Object(PHPStan\Analyser\MutatingScope))
#3 phar://project_root/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(401):
PHPStan\Analyser\NodeScopeResolver->processStmtNode(Object(PhpParser\Node\Stmt\Class_), Object(PHPStan\Analyser\MutatingScope), Object(Closure), Object(PHPStan\Analyser\StatementContext))

@VincentLanglet
Copy link
Contributor

Current work in progress is here #535 if you want to try the branch on your side.

@ondrejmirtes
Copy link
Member

Full compatibility with ORM 3.0 and DBAL 4.0 has been merged (#535) and will be released shortly as phpstan-doctrine 1.3.61.

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 13, 2024
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

6 participants