Skip to content

Commit 6a4f4f3

Browse files
authored
fetchAll(PDO::FETCH_KEY_PAIR) has incorrect return type with an extra array (#307)
* Fix test expectations * Update PdoStatementFetchDynamicReturnTypeExtension.php
1 parent ce11ba6 commit 6a4f4f3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ private function inferType(MethodReflection $methodReflection, MethodCall $metho
127127
}
128128

129129
if ('fetchAll' === $methodReflection->getName()) {
130+
if (QueryReflector::FETCH_TYPE_KEY_VALUE === $fetchType) {
131+
return $rowType;
132+
}
130133
return new ArrayType(new IntegerType(), $rowType);
131134
}
132135

tests/default/data/pdo-stmt-fetch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function fetchAll(PDO $pdo)
3939
assertType('array<int, int<0, 4294967295>>', $all);
4040

4141
$all = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
42-
assertType('array<int, array<string, int<0, 4294967295>>>', $all);
42+
assertType('array<string, int<0, 4294967295>>', $all);
4343

4444
$all = $stmt->fetchAll(PDO::FETCH_CLASS, MyRowClass::class);
4545
assertType('array<int, staabm\PHPStanDba\Tests\Fixture\MyRowClass>', $all);

0 commit comments

Comments
 (0)