Skip to content

Commit ac2596a

Browse files
authored
support @phpstandba-inference-placeholder on calls via variable (#434)
1 parent 5889874 commit ac2596a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/QueryReflection/QueryReflection.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,19 @@ private function resolveQueryExpr(Expr $queryExpr, Scope $scope): ?string
188188
/**
189189
* @throws UnresolvableQueryException
190190
*/
191-
private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope): ?string
191+
private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $resolveVariables = true): ?string
192192
{
193+
if (true === $resolveVariables && $queryExpr instanceof Expr\Variable) {
194+
$finder = new ExpressionFinder();
195+
$assignExpr = $finder->findQueryStringExpression($queryExpr);
196+
197+
if (null !== $assignExpr) {
198+
return $this->resolveQueryStringExpr($assignExpr, $scope);
199+
}
200+
201+
return $this->resolveQueryStringExpr($queryExpr, $scope, false);
202+
}
203+
193204
if ($queryExpr instanceof Expr\CallLike) {
194205
$methodReflection = null;
195206
if ($queryExpr instanceof Expr\StaticCall) {

tests/default/data/inference-placeholder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ public function fetchOneWithDynamicQueryPart(Connection $conn, string $email)
1818
assertType('string|false', $fetchResult);
1919
}
2020

21+
public function fetchOneWithDynamicQueryPartViaVariable(Connection $conn, string $email)
22+
{
23+
$dynamicPart = self::dynamicWhere(rand(0, 100));
24+
$query = 'SELECT email, adaid FROM ada WHERE email = :email AND '.$dynamicPart;
25+
$fetchResult = $conn->fetchOne($query, ['email' => $email]);
26+
assertType('string|false', $fetchResult);
27+
}
28+
2129
/**
2230
* simulating a dynamic where part, not relevant for the query overall result.
2331
*

0 commit comments

Comments
 (0)