Skip to content

Commit

Permalink
support @phpstandba-inference-placeholder on calls via variable (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Oct 2, 2022
1 parent 5889874 commit ac2596a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/QueryReflection/QueryReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,19 @@ private function resolveQueryExpr(Expr $queryExpr, Scope $scope): ?string
/**
* @throws UnresolvableQueryException
*/
private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope): ?string
private function resolveQueryStringExpr(Expr $queryExpr, Scope $scope, bool $resolveVariables = true): ?string
{
if (true === $resolveVariables && $queryExpr instanceof Expr\Variable) {
$finder = new ExpressionFinder();
$assignExpr = $finder->findQueryStringExpression($queryExpr);

if (null !== $assignExpr) {
return $this->resolveQueryStringExpr($assignExpr, $scope);
}

return $this->resolveQueryStringExpr($queryExpr, $scope, false);
}

if ($queryExpr instanceof Expr\CallLike) {
$methodReflection = null;
if ($queryExpr instanceof Expr\StaticCall) {
Expand Down
8 changes: 8 additions & 0 deletions tests/default/data/inference-placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public function fetchOneWithDynamicQueryPart(Connection $conn, string $email)
assertType('string|false', $fetchResult);
}

public function fetchOneWithDynamicQueryPartViaVariable(Connection $conn, string $email)
{
$dynamicPart = self::dynamicWhere(rand(0, 100));
$query = 'SELECT email, adaid FROM ada WHERE email = :email AND '.$dynamicPart;
$fetchResult = $conn->fetchOne($query, ['email' => $email]);
assertType('string|false', $fetchResult);
}

/**
* simulating a dynamic where part, not relevant for the query overall result.
*
Expand Down

0 comments on commit ac2596a

Please sign in to comment.