Skip to content

Commit 619b186

Browse files
staabmclxmstaab
andauthored
doctrine-dbal: implement Connection->iterateColumn() (#210)
Co-authored-by: Markus Staab <[email protected]>
1 parent e2a1ae1 commit 619b186

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/DoctrineReflection/DoctrineReflection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function fetchResultType(MethodReflection $methodReflection, Type $result
3030
$fetchType = QueryReflector::FETCH_TYPE_ONE;
3131
break;
3232
case 'fetchfirstcolumn':
33+
case 'iteratecolumn':
3334
$fetchType = QueryReflector::FETCH_TYPE_FIRST_COL;
3435
break;
3536
case 'fetchnumeric':
@@ -57,6 +58,10 @@ public function fetchResultType(MethodReflection $methodReflection, Type $result
5758
return $valueTypes[$i];
5859
}
5960
if (QueryReflector::FETCH_TYPE_FIRST_COL === $fetchType) {
61+
if (\in_array($usedMethod, ['iteratecolumn'], true)) {
62+
return new GenericObjectType(Traversable::class, [new IntegerType(), $valueTypes[$i]]);
63+
}
64+
6065
return new ArrayType(IntegerRangeType::fromInterval(0, null), $valueTypes[$i]);
6166
}
6267

src/Extensions/DoctrineConnectionFetchDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function getClass(): string
2828

2929
public function isMethodSupported(MethodReflection $methodReflection): bool
3030
{
31-
return \in_array(strtolower($methodReflection->getName()), ['fetchone', 'fetchfirstcolumn', 'fetchassociative', 'fetchallassociative', 'fetchnumeric', 'fetchallnumeric', 'iterateassociative', 'iteratenumeric', 'iterateallnumeric'], true);
31+
return \in_array(strtolower($methodReflection->getName()), ['fetchone', 'fetchfirstcolumn', 'fetchassociative', 'fetchallassociative', 'fetchnumeric', 'fetchallnumeric', 'iteratecolumn', 'iterateassociative', 'iteratenumeric', 'iterateallnumeric'], true);
3232
}
3333

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

tests/data/doctrine-dbal.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ public function iterateNumeric(Connection $conn)
8383
assertType('Traversable<int, array{string, int<0, 4294967295>, int<-128, 127>, int<-128, 127>}>', $fetchResult);
8484
}
8585

86+
public function iterateColumn(Connection $conn)
87+
{
88+
$query = 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = ?';
89+
$fetchResult = $conn->iterateColumn($query, [1]);
90+
assertType('Traversable<int, string>', $fetchResult);
91+
}
92+
8693
public function fetchOne(Connection $conn)
8794
{
8895
$query = 'SELECT email, adaid, gesperrt, freigabe1u1 FROM ada WHERE adaid = ?';

0 commit comments

Comments
 (0)