Skip to content

Commit 33b0aaa

Browse files
staabmclxmstaab
andauthored
drop symplify/phpstan-extensions dependency (#368)
* drop symplify/phpstan-extensions dependency * cs * handle UnresolvableQueryException Co-authored-by: Markus Staab <[email protected]>
1 parent fbab1b3 commit 33b0aaa

24 files changed

+2762
-1351
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"phpstan/phpstan-phpunit": "^1.0",
1818
"phpstan/phpstan-strict-rules": "^1.1",
1919
"phpunit/phpunit": "^9",
20-
"symplify/phpstan-extensions": "^10.0",
2120
"vlucas/phpdotenv": "^5.4"
2221
},
2322
"conflicts": {

src/Extensions/MysqliQueryDynamicReturnTypeExtension.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use staabm\PHPStanDba\MysqliReflection\MysqliResultObjectType;
2323
use staabm\PHPStanDba\QueryReflection\QueryReflection;
2424
use staabm\PHPStanDba\QueryReflection\QueryReflector;
25+
use staabm\PHPStanDba\UnresolvableQueryException;
2526

2627
final class MysqliQueryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension, DynamicFunctionReturnTypeExtension
2728
{
@@ -63,7 +64,12 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
6364
return $defaultReturn;
6465
}
6566

66-
$resultType = $this->inferResultType($args[1]->value, $scope);
67+
try {
68+
$resultType = $this->inferResultType($args[1]->value, $scope);
69+
} catch (UnresolvableQueryException $e) {
70+
return $defaultReturn;
71+
}
72+
6773
if (null !== $resultType) {
6874
return $resultType;
6975
}
@@ -88,14 +94,22 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
8894
return $defaultReturn;
8995
}
9096

91-
$resultType = $this->inferResultType($args[0]->value, $scope);
97+
try {
98+
$resultType = $this->inferResultType($args[0]->value, $scope);
99+
} catch (UnresolvableQueryException $e) {
100+
return $defaultReturn;
101+
}
102+
92103
if (null !== $resultType) {
93104
return $resultType;
94105
}
95106

96107
return $defaultReturn;
97108
}
98109

110+
/**
111+
* @throws UnresolvableQueryException
112+
*/
99113
private function inferResultType(Expr $queryExpr, Scope $scope): ?Type
100114
{
101115
$queryReflection = new QueryReflection();

src/Extensions/PdoQueryDynamicReturnTypeExtension.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use staabm\PHPStanDba\PdoReflection\PdoStatementReflection;
2020
use staabm\PHPStanDba\QueryReflection\QueryReflection;
2121
use staabm\PHPStanDba\QueryReflection\QueryReflector;
22+
use staabm\PHPStanDba\UnresolvableQueryException;
2223

2324
final class PdoQueryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
2425
{
@@ -63,14 +64,22 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
6364
return $defaultReturn;
6465
}
6566

66-
$resultType = $this->inferType($methodCall, $args[0]->value, $scope);
67+
try {
68+
$resultType = $this->inferType($methodCall, $args[0]->value, $scope);
69+
} catch (UnresolvableQueryException $e) {
70+
return $defaultReturn;
71+
}
72+
6773
if (null !== $resultType) {
6874
return $resultType;
6975
}
7076

7177
return $defaultReturn;
7278
}
7379

80+
/**
81+
* @throws UnresolvableQueryException
82+
*/
7483
private function inferType(MethodCall $methodCall, Expr $queryExpr, Scope $scope): ?Type
7584
{
7685
$args = $methodCall->getArgs();

src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Type\Type;
1717
use staabm\PHPStanDba\PdoReflection\PdoStatementReflection;
1818
use staabm\PHPStanDba\QueryReflection\QueryReflection;
19+
use staabm\PHPStanDba\UnresolvableQueryException;
1920

2021
final class PdoStatementExecuteTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
2122
{
@@ -41,14 +42,22 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
4142
// keep original param name because named-parameters
4243
$methodCall = $node;
4344

44-
$inferedType = $this->inferStatementType($methodReflection, $methodCall, $scope);
45+
try {
46+
$inferedType = $this->inferStatementType($methodReflection, $methodCall, $scope);
47+
} catch (UnresolvableQueryException $e) {
48+
return new SpecifiedTypes();
49+
}
50+
4551
if (null !== $inferedType) {
4652
return $this->typeSpecifier->create($methodCall->var, $inferedType, TypeSpecifierContext::createTruthy(), true);
4753
}
4854

4955
return new SpecifiedTypes();
5056
}
5157

58+
/**
59+
* @throws UnresolvableQueryException
60+
*/
5261
private function inferStatementType(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type
5362
{
5463
$args = $methodCall->getArgs();

0 commit comments

Comments
 (0)