Skip to content

Commit 7ce54d8

Browse files
staabmclxmstaab
andauthored
fix phpdoc parsing with whitespaces/contents after values (#438)
Co-authored-by: Markus Staab <[email protected]>
1 parent 8e6836a commit 7ce54d8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/PhpDoc/PhpDocUtil.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function matchTaintEscape($callLike, Scope $scope): ?string
3030
// atm no resolved phpdoc for methods
3131
// see https://github.com/phpstan/phpstan/discussions/7657
3232
$phpDocString = $methodReflection->getDocComment();
33-
if (null !== $phpDocString && preg_match('/@psalm-taint-escape\s+(\S+)$/m', $phpDocString, $matches)) {
33+
if (null !== $phpDocString && preg_match('/@psalm-taint-escape\s+(\S+).*$/m', $phpDocString, $matches)) {
3434
return $matches[1];
3535
}
3636
}
@@ -91,7 +91,7 @@ private static function matchStringAnnotation(string $annotation, $callLike, Sco
9191
// atm no resolved phpdoc for methods
9292
// see https://github.com/phpstan/phpstan/discussions/7657
9393
$phpDocString = $methodReflection->getDocComment();
94-
if (null !== $phpDocString && preg_match('/'.$annotation.'\s+(.+)$/m', $phpDocString, $matches)) {
94+
if (null !== $phpDocString && preg_match('/'.$annotation.'\s+(\S+).*$/m', $phpDocString, $matches)) {
9595
$placeholder = $matches[1];
9696

9797
if (\in_array($placeholder[0], ['"', "'"], true)) {

tests/default/data/inference-placeholder.php

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ public function fetchOneWithDynamicQueryPartViaVariable(Connection $conn, string
2626
assertType('string|false', $fetchResult);
2727
}
2828

29+
public function bug439(Connection $conn, string $email)
30+
{
31+
$query = 'SELECT email, adaid FROM ada WHERE email = :email AND '.$this->stuffAfterPlaceholder(rand(0, 100));
32+
$fetchResult = $conn->fetchOne($query, ['email' => $email]);
33+
assertType('string|false', $fetchResult);
34+
}
35+
2936
/**
3037
* simulating a dynamic where part, not relevant for the query overall result.
3138
*
@@ -61,4 +68,14 @@ private static function staticDynamicWhere(int $i)
6168

6269
return implode(' AND ', $where);
6370
}
71+
72+
/**
73+
* @phpstandba-inference-placeholder '1=1' <-- anything behind placeholder value
74+
*
75+
* @return string
76+
*/
77+
private function stuffAfterPlaceholder(int $i)
78+
{
79+
return '';
80+
}
6481
}

0 commit comments

Comments
 (0)