Skip to content

Commit 6a25c9d

Browse files
authored
QueryBuilderDqlRule: mention DQL for BranchingQueryBuilderType
1 parent f6081cf commit 6a25c9d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/Rules/Doctrine/ORM/QueryBuilderDqlRule.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,15 @@ public function processNode(Node $node, Scope $scope): array
118118
$message .= sprintf("\nDQL: %s", $dql->getValue());
119119
}
120120

121+
$builder = RuleErrorBuilder::message($message)
122+
->identifier('doctrine.dql');
123+
124+
if (count($dqls) > 1) {
125+
$builder->addTip('Detected from DQL branch: ' . $dql->getValue());
126+
}
127+
121128
// Use message as index to prevent duplicate
122-
$messages[$message] = RuleErrorBuilder::message($message)
123-
->identifier('doctrine.dql')
124-
->build();
129+
$messages[$message] = $builder->build();
125130
} catch (AssertionError $e) {
126131
continue;
127132
}

tests/Rules/Doctrine/ORM/QueryBuilderDqlRuleSlowTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,22 @@ public function testRuleBranches(): void
112112
[
113113
'QueryBuilder: [Semantical Error] line 0, col 58 near \'p.id = 1\': Error: \'p\' is not defined.',
114114
59,
115+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e WHERE p.id = 1',
115116
],
116117
[
117118
'QueryBuilder: [Semantical Error] line 0, col 93 near \'t.id = 1\': Error: \'t\' is not defined.',
118119
90,
120+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e INNER JOIN e.parent p WHERE p.id = 1 AND t.id = 1',
119121
],
120122
[
121123
'QueryBuilder: [Semantical Error] line 0, col 95 near \'foo = 1\': Error: Class PHPStan\Rules\Doctrine\ORM\MyEntity has no field or association named foo',
122124
107,
125+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e INNER JOIN e.parent p WHERE p.id = 1 AND e.foo = 1',
123126
],
124127
[
125128
'QueryBuilder: [Semantical Error] line 0, col 93 near \'t.id = 1\': Error: \'t\' is not defined.',
126129
107,
130+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e INNER JOIN e.parent p WHERE p.id = 1 AND t.id = 1',
127131
],
128132
];
129133
$this->analyse([__DIR__ . '/data/query-builder-branches-dql.php'], $errors);

tests/Rules/Doctrine/ORM/QueryBuilderDqlRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,22 @@ public function testRuleBranches(): void
113113
[
114114
'QueryBuilder: [Semantical Error] line 0, col 58 near \'p.id = 1\': Error: \'p\' is not defined.',
115115
59,
116+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e WHERE p.id = 1',
116117
],
117118
[
118119
'QueryBuilder: [Semantical Error] line 0, col 93 near \'t.id = 1\': Error: \'t\' is not defined.',
119120
90,
121+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e INNER JOIN e.parent p WHERE p.id = 1 AND t.id = 1',
120122
],
121123
[
122124
'QueryBuilder: [Semantical Error] line 0, col 95 near \'foo = 1\': Error: Class PHPStan\Rules\Doctrine\ORM\MyEntity has no field or association named foo',
123125
107,
126+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e INNER JOIN e.parent p WHERE p.id = 1 AND e.foo = 1',
124127
],
125128
[
126129
'QueryBuilder: [Semantical Error] line 0, col 93 near \'t.id = 1\': Error: \'t\' is not defined.',
127130
107,
131+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e INNER JOIN e.parent p WHERE p.id = 1 AND t.id = 1',
128132
],
129133
];
130134
$this->analyse([__DIR__ . '/data/query-builder-branches-dql.php'], $errors);
@@ -151,6 +155,7 @@ public function testBranchingPerformance(): void
151155
[
152156
'QueryBuilder: [Semantical Error] line 0, col 58 near \'p.id = 1 AND\': Error: \'p\' is not defined.',
153157
121,
158+
'Detected from DQL branch: SELECT e FROM PHPStan\Rules\Doctrine\ORM\MyEntity e WHERE p.id = 1 AND p.id = 3 AND p.id = 5 AND p.id = 7 AND p.id = 9 AND p.id = 11 AND p.id = 13 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15 AND p.id = 15',
154159
],
155160
]);
156161
}

0 commit comments

Comments
 (0)