Skip to content

Conversation

@janedbal
Copy link
Contributor

Separated from #506.

This is needed for proper nullability detection (when no group by is used, single row is always returned). Previously, it was working only when SUM was in first level in select AST. But it can be anywhere inside the tree, so we need pre-walk the AST to detect it.

use Doctrine\ORM\Query\AST;
use function is_string;

class QueryAggregateFunctionDetectorTreeWalker extends Query\TreeWalkerAdapter
Copy link
Contributor Author

@janedbal janedbal Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AST traversal logic is copied from Doctrine's SqlWalker. But since they do double-dispatch which is not possible here, those places are mostly replaced with generic doWalkNode.

I also prefixed all methods with do so that this works in dbal3 and dbal4 (where TreeWalker interface lost most of its methods).

$this->constantArray([
[
new ConstantStringType('many'),
TypeCombinator::addNull(new ObjectType(Many::class)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wont be nullable in the old implementation, which is wrong.

@ondrejmirtes ondrejmirtes merged commit 3369068 into phpstan:1.4.x Jun 25, 2024
@ondrejmirtes
Copy link
Member

Thank you!

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 this pull request may close these issues.

2 participants