Skip to content

Commit adab718

Browse files
committed
inference with spread
1 parent 40c9d67 commit adab718

File tree

6 files changed

+161
-49
lines changed

6 files changed

+161
-49
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpstan-dba-pdo-mysql.cache

Lines changed: 1 addition & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/default/config/.phpunit-phpstan-dba-mysqli.cache

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/default/config/.phpunit-phpstan-dba-pdo-mysql.cache

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/default/data/pdo-prepare.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,34 @@ public function noInferenceOnBug196(PDO $pdo, array $minorPhpVersions, \DateTime
200200
assertType('array<int|string, mixed>', $row);
201201
}
202202
}
203+
204+
/** @param list<int> $ids */
205+
public function spreadIds(PDO $pdo, array $ids)
206+
{
207+
$query = 'SELECT adaid FROM ada WHERE adaid IN ('. self::inPlaceholders($ids) .')';
208+
$stmt = $pdo->prepare($query);
209+
$stmt->execute(...$ids);
210+
211+
foreach ($stmt as $row) {
212+
assertType('array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}', $row);
213+
}
214+
}
215+
216+
/**
217+
* Returns a string containing all required "?"-placeholders to pass $ids into a IN()-expression.
218+
*
219+
* @phpstandba-inference-placeholder '?'
220+
*
221+
* @param non-empty-array<int|string> $ids
222+
*
223+
* @return literal-string
224+
*/
225+
public static function inPlaceholders(array $ids): string
226+
{
227+
// no matter whether $ids contains user input or not,
228+
// we can safely say what we return here will no longer contain user input.
229+
// therefore we type the return with "literal-string"
230+
return implode(',', array_fill(0, count($ids), '?'));
231+
}
232+
203233
}

tests/rules/data/bug-749.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function inPlaceholders(array $ids): string
8080
{
8181
// no matter whether $ids contains user input or not,
8282
// we can safely say what we return here will no longer contain user input.
83-
// therefore we type the return with "literal-string", so we don't get errors like
83+
// therefore we type the return with "literal-string"
8484
return implode(',', array_fill(0, count($ids), '?'));
8585
}
8686
}

0 commit comments

Comments
 (0)