Skip to content

Commit cc1678a

Browse files
authored
Support iterable typed parameter (#693)
1 parent 0adf44a commit cc1678a

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/QueryReflection/QuerySimulation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function simulateParamValueType(Type $paramType, bool $preparedPar
3434
return (string) $paramType->getValue();
3535
}
3636

37-
if ($paramType->isArray()->yes()) {
37+
if ($paramType->isIterable()->yes()) {
3838
return self::simulateParamValueType($paramType->getIterableValueType(), $preparedParam);
3939
}
4040

tests/default/data/pdo-prepare.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ public function specifiedArray(PDO $pdo, array $idsToUpdate, string $time)
136136
assertType('PDOStatement<array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}>', $stmt);
137137
}
138138

139+
/**
140+
* @param iterable<int> $idsToUpdate
141+
*/
142+
public function specifiedIterable(PDO $pdo, iterable $idsToUpdate, string $time)
143+
{
144+
$query = 'SELECT adaid FROM ada WHERE adaid IN (:ids) AND email LIKE :time';
145+
$stmt = $pdo->prepare($query);
146+
$stmt->execute([
147+
'ids' => $idsToUpdate,
148+
'time' => $time,
149+
]);
150+
assertType('PDOStatement<array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>}>', $stmt);
151+
}
152+
139153
public function noInferenceOnBug196(PDO $pdo, array $minorPhpVersions, \DateTimeImmutable $updateDate)
140154
{
141155
$sumQueries = [];

tests/rules/UnresolvableQueryMethodRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ public function testBug547(): void
7878
{
7979
$this->analyse([__DIR__ . '/data/bug-547.php'], []);
8080
}
81+
82+
public function testBug676(): void
83+
{
84+
$this->analyse([__DIR__ . '/data/bug-676.php'], []);
85+
}
8186
}

tests/rules/data/bug-676.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Test;
4+
5+
use Doctrine\DBAL\Connection;
6+
7+
class Test
8+
{
9+
private Connection $connection;
10+
11+
public function getIds(iterable $ids): array
12+
{
13+
return $this
14+
->connection
15+
->executeQuery(
16+
'SELECT id FROM table WHERE id IN (:list)',
17+
['list' => $ids],
18+
['list' => DBAL\Connection::PARAM_INT_ARRAY],
19+
)
20+
->fetchFirstColumn();
21+
}
22+
}

0 commit comments

Comments
 (0)