Skip to content

Commit 772b4cd

Browse files
staabmclxmstaab
andauthored
simplify PdoStatementExecuteTypeSpecifyingExtension (#259)
Co-authored-by: Markus Staab <[email protected]>
1 parent c1a327c commit 772b4cd

File tree

5 files changed

+153
-12
lines changed

5 files changed

+153
-12
lines changed

src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
4242
{
4343
// keep original param name because named-parameters
4444
$methodCall = $node;
45-
$stmtType = $scope->getType($methodCall->var);
4645

4746
$inferedType = $this->inferStatementType($methodReflection, $methodCall, $scope);
4847
if (null !== $inferedType) {
4948
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), true);
5049
}
5150

52-
return $this->typeSpecifier->create($methodCall->var, $stmtType, TypeSpecifierContext::createTruthy());
51+
return new SpecifiedTypes();
5352
}
5453

5554
private function inferStatementType(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type

src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@
1212
use PHPStan\Reflection\MethodReflection;
1313
use PHPStan\Reflection\ParametersAcceptorSelector;
1414
use PHPStan\Type\ArrayType;
15-
use PHPStan\Type\Constant\ConstantArrayType;
16-
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
1715
use PHPStan\Type\Constant\ConstantBooleanType;
1816
use PHPStan\Type\Constant\ConstantIntegerType;
19-
use PHPStan\Type\Constant\ConstantStringType;
2017
use PHPStan\Type\DynamicMethodReturnTypeExtension;
21-
use PHPStan\Type\Generic\GenericObjectType;
2218
use PHPStan\Type\IntegerType;
2319
use PHPStan\Type\MixedType;
2420
use PHPStan\Type\Type;
@@ -85,7 +81,7 @@ private function inferType(MethodReflection $methodReflection, MethodCall $metho
8581

8682
$pdoStatementReflection = new PdoStatementReflection();
8783
$resultType = $pdoStatementReflection->getStatementResultType($statementType, $fetchType);
88-
if ($resultType === null) {
84+
if (null === $resultType) {
8985
return null;
9086
}
9187

src/PdoReflection/PdoStatementReflection.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use PHPStan\Type\Generic\GenericObjectType;
1616
use PHPStan\Type\Type;
1717
use staabm\PHPStanDba\QueryReflection\ExpressionFinder;
18-
use staabm\PHPStanDba\QueryReflection\QueryReflection;
19-
use staabm\PHPStanDba\QueryReflection\QueryReflector;
2018

2119
final class PdoStatementReflection
2220
{
@@ -36,11 +34,14 @@ public function findPrepareQueryStringExpression(MethodReflection $methodReflect
3634
}
3735

3836
/**
39-
* // the following param doesnt work, see phpstan bug https://github.com/phpstan/phpstan/issues/6577
37+
* // the following param doesnt work, see phpstan bug https://github.com/phpstan/phpstan/issues/6577.
38+
*
4039
* @xx-param PDO::FETCH* $fetchType
40+
*
4141
* @return Type|null
4242
*/
43-
public function getStatementResultType(Type $statementType, int $fetchType) {
43+
public function getStatementResultType(Type $statementType, int $fetchType)
44+
{
4445
if (!$statementType instanceof GenericObjectType) {
4546
return null;
4647
}

0 commit comments

Comments
 (0)