Skip to content

Commit be1006a

Browse files
clxmstaabstaabm
authored andcommitted
doctrine-dbal: support Result->fetchOne() type inference
1 parent 128cb58 commit be1006a

File tree

3 files changed

+14
-263
lines changed

3 files changed

+14
-263
lines changed

.phpstan-dba.cache

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

src/Extensions/DoctrineResultDynamicReturnTypeExtension.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@
2121

2222
final class DoctrineResultDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
2323
{
24+
public const METHODS = [
25+
'fetchone',
26+
'columncount',
27+
'fetchfirstcolumn',
28+
'fetchnumeric',
29+
'fetchallnumeric',
30+
'fetchassociative',
31+
'fetchallassociative',
32+
];
33+
2434
public function getClass(): string
2535
{
2636
return Result::class;
2737
}
2838

2939
public function isMethodSupported(MethodReflection $methodReflection): bool
3040
{
31-
return \in_array(strtolower($methodReflection->getName()), ['columncount', 'fetchfirstcolumn', 'fetchnumeric', 'fetchallnumeric', 'fetchassociative', 'fetchallassociative'], true);
41+
return \in_array(strtolower($methodReflection->getName()), self::METHODS, true);
3242
}
3343

3444
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type

tests/data/doctrine-dbal.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public function foo(Connection $conn)
1313
$result = $conn->query('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada');
1414
assertType('Doctrine\DBAL\Result<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>, gesperrt: int<-128, 127>, 2: int<-128, 127>, freigabe1u1: int<-128, 127>, 3: int<-128, 127>}>', $result);
1515

16+
$fetch = $result->fetchOne();
17+
assertType('string', $fetch);
18+
1619
$fetch = $result->fetchNumeric();
1720
assertType('array{string, int<0, 4294967295>, int<-128, 127>, int<-128, 127>}|false', $fetch);
1821

0 commit comments

Comments
 (0)