Skip to content

Commit 6a172b0

Browse files
authored
phpstan 1.9 fixes (#445)
1 parent 7ce54d8 commit 6a172b0

4 files changed

+22
-13
lines changed

src/Rules/QueryPlanAnalyzerRule.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPStan\Rules\Rule;
1414
use PHPStan\Rules\RuleError;
1515
use PHPStan\Rules\RuleErrorBuilder;
16+
use PHPStan\ShouldNotHappenException;
1617
use PHPStan\Type\MixedType;
1718
use PHPStan\Type\ObjectType;
1819
use staabm\PHPStanDba\QueryReflection\QueryReflection;
@@ -65,24 +66,24 @@ public function processNode(Node $callLike, Scope $scope): array
6566
return [];
6667
}
6768

68-
$unsupportedMethod = true;
6969
$queryArgPosition = null;
7070
foreach ($this->classMethods as $classMethod) {
71-
sscanf($classMethod, '%[^::]::%[^#]#%s', $className, $methodName, $queryArgPosition);
71+
sscanf($classMethod, '%[^::]::%[^#]#%i', $className, $methodName, $queryArgPosition);
72+
if (!is_string($className) || !is_string($methodName) || !is_int($queryArgPosition)) {
73+
throw new ShouldNotHappenException('Invalid classMethod definition');
74+
}
7275

7376
if ($methodName === $methodReflection->getName() &&
7477
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))) {
75-
$unsupportedMethod = false;
7678
break;
7779
}
7880
}
7981

80-
if ($unsupportedMethod) {
82+
if ($queryArgPosition === null) {
8183
return [];
8284
}
8385

8486
$args = $callLike->getArgs();
85-
8687
if (!\array_key_exists($queryArgPosition, $args)) {
8788
return [];
8889
}

src/Rules/SyntaxErrorInPreparedStatementMethodRule.php

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPStan\Rules\Rule;
1414
use PHPStan\Rules\RuleError;
1515
use PHPStan\Rules\RuleErrorBuilder;
16+
use PHPStan\ShouldNotHappenException;
1617
use PHPStan\Type\MixedType;
1718
use PHPStan\Type\ObjectType;
1819
use staabm\PHPStanDba\QueryReflection\PlaceholderValidation;
@@ -68,6 +69,9 @@ public function processNode(Node $callLike, Scope $scope): array
6869
$unsupportedMethod = true;
6970
foreach ($this->classMethods as $classMethod) {
7071
sscanf($classMethod, '%[^::]::%s', $className, $methodName);
72+
if (!is_string($className) || !is_string($methodName)) {
73+
throw new ShouldNotHappenException('Invalid classMethod definition');
74+
}
7175

7276
if ($methodName === $methodReflection->getName() &&
7377
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))) {

src/Rules/SyntaxErrorInQueryFunctionRule.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Reflection\ReflectionProvider;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleErrorBuilder;
13+
use PHPStan\ShouldNotHappenException;
1314
use PHPStan\Type\MixedType;
1415
use staabm\PHPStanDba\QueryReflection\QueryReflection;
1516
use staabm\PHPStanDba\Tests\SyntaxErrorInQueryFunctionRuleTest;
@@ -57,18 +58,19 @@ public function processNode(Node $node, Scope $scope): array
5758
return [];
5859
}
5960

60-
$unsupportedFunction = true;
6161
$queryArgPosition = null;
6262
foreach ($this->functionNames as $functionName) {
63-
sscanf($functionName, '%[^#]#%s', $functionName, $queryArgPosition);
63+
sscanf($functionName, '%[^#]#%i', $functionName, $queryArgPosition);
64+
if (!is_string($functionName) || !is_int($queryArgPosition)) {
65+
throw new ShouldNotHappenException('Invalid functionName definition');
66+
}
6467

6568
if (strtolower($functionName) === strtolower($calledFunctionName)) {
66-
$unsupportedFunction = false;
6769
break;
6870
}
6971
}
7072

71-
if ($unsupportedFunction) {
73+
if ($queryArgPosition === null) {
7274
return [];
7375
}
7476

src/Rules/SyntaxErrorInQueryMethodRule.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Analyser\Scope;
1010
use PHPStan\Rules\Rule;
1111
use PHPStan\Rules\RuleErrorBuilder;
12+
use PHPStan\ShouldNotHappenException;
1213
use PHPStan\Type\MixedType;
1314
use staabm\PHPStanDba\QueryReflection\QueryReflection;
1415
use staabm\PHPStanDba\UnresolvableQueryException;
@@ -49,19 +50,20 @@ public function processNode(Node $node, Scope $scope): array
4950
return [];
5051
}
5152

52-
$unsupportedMethod = true;
5353
$queryArgPosition = null;
5454
foreach ($this->classMethods as $classMethod) {
55-
sscanf($classMethod, '%[^::]::%[^#]#%s', $className, $methodName, $queryArgPosition);
55+
sscanf($classMethod, '%[^::]::%[^#]#%i', $className, $methodName, $queryArgPosition);
56+
if (!is_string($className) || !is_string($methodName) || !is_int($queryArgPosition)) {
57+
throw new ShouldNotHappenException('Invalid classMethod definition');
58+
}
5659

5760
if ($methodName === $methodReflection->getName() &&
5861
($methodReflection->getDeclaringClass()->getName() === $className || $methodReflection->getDeclaringClass()->isSubclassOf($className))) {
59-
$unsupportedMethod = false;
6062
break;
6163
}
6264
}
6365

64-
if ($unsupportedMethod) {
66+
if ($queryArgPosition === null) {
6567
return [];
6668
}
6769

0 commit comments

Comments
 (0)