Skip to content

Commit dbae25f

Browse files
staabmclxmstaab
andauthored
simplify PdoStatementColumnCountDynamicReturnTypeExtension (#325)
Co-authored-by: Markus Staab <[email protected]>
1 parent 51e2eca commit dbae25f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Extensions/PdoStatementColumnCountDynamicReturnTypeExtension.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
use PHPStan\Type\Constant\ConstantArrayType;
1313
use PHPStan\Type\Constant\ConstantIntegerType;
1414
use PHPStan\Type\DynamicMethodReturnTypeExtension;
15-
use PHPStan\Type\Generic\GenericObjectType;
1615
use PHPStan\Type\Type;
17-
use staabm\PHPStanDba\PdoReflection\PdoStatementReflection;
16+
use staabm\PHPStanDba\PdoReflection\PdoStatementObjectType;
1817
use staabm\PHPStanDba\QueryReflection\QueryReflector;
1918

2019
final class PdoStatementColumnCountDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
@@ -31,13 +30,12 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3130

3231
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3332
{
34-
$pdoStatementReflection = new PdoStatementReflection();
3533
$defaultReturn = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
3634

3735
$statementType = $scope->getType($methodCall->var);
3836

39-
if ($statementType instanceof GenericObjectType) {
40-
$rowType = $pdoStatementReflection->getRowType($statementType, QueryReflector::FETCH_TYPE_NUMERIC);
37+
if ($statementType instanceof PdoStatementObjectType) {
38+
$rowType = $statementType->newWithFetchType(QueryReflector::FETCH_TYPE_NUMERIC)->getRowType();
4139
if ($rowType instanceof ConstantArrayType) {
4240
return new ConstantIntegerType(\count($rowType->getKeyTypes()));
4341
}

0 commit comments

Comments
 (0)