Skip to content

Commit dd1a4e7

Browse files
authored
enable phpstan/phpstan-deprecation-rules (#544)
1 parent c64db58 commit dd1a4e7

File tree

4 files changed

+207
-12
lines changed

4 files changed

+207
-12
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"dibi/dibi": "^4.2",
1616
"php-parallel-lint/php-parallel-lint": "^1.3",
1717
"phpstan/extension-installer": "^1.2",
18+
"phpstan/phpstan-deprecation-rules": "^1.1",
1819
"phpstan/phpstan-php-parser": "^1.1",
1920
"phpstan/phpstan-phpunit": "^1.0",
2021
"phpstan/phpstan-strict-rules": "^1.1",

phpstan-baseline.neon

Lines changed: 193 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,155 @@ parameters:
1515
count: 1
1616
path: src/DbSchema/SchemaHasherMysql.php
1717

18+
-
19+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
20+
count: 1
21+
path: src/DoctrineReflection/DoctrineReflection.php
22+
23+
-
24+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
25+
count: 1
26+
path: src/DoctrineReflection/DoctrineReflection.php
27+
28+
-
29+
message: "#^Class Doctrine\\\\DBAL\\\\Result not found\\.$#"
30+
count: 1
31+
path: src/DoctrineReflection/DoctrineResultObjectType.php
32+
33+
-
34+
message: "#^Class Doctrine\\\\DBAL\\\\Statement not found\\.$#"
35+
count: 1
36+
path: src/DoctrineReflection/DoctrineStatementObjectType.php
37+
38+
-
39+
message: """
40+
#^Call to deprecated method resolveQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
41+
use resolveQueryStrings\\(\\) instead$#
42+
"""
43+
count: 1
44+
path: src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php
45+
46+
-
47+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
48+
count: 1
49+
path: src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php
50+
51+
-
52+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
53+
count: 2
54+
path: src/Extensions/DibiConnectionFetchDynamicReturnTypeExtension.php
55+
56+
-
57+
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
58+
count: 1
59+
path: src/Extensions/DoctrineConnectionExecuteQueryDynamicReturnTypeExtension.php
60+
61+
-
62+
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
63+
count: 1
64+
path: src/Extensions/DoctrineConnectionFetchDynamicReturnTypeExtension.php
65+
66+
-
67+
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
68+
count: 1
69+
path: src/Extensions/DoctrineConnectionPrepareDynamicReturnTypeExtension.php
70+
71+
-
72+
message: "#^Class Doctrine\\\\DBAL\\\\Connection not found\\.$#"
73+
count: 1
74+
path: src/Extensions/DoctrineConnectionQueryDynamicReturnTypeExtension.php
75+
76+
-
77+
message: "#^Class Doctrine\\\\DBAL\\\\Result not found\\.$#"
78+
count: 1
79+
path: src/Extensions/DoctrineResultDynamicReturnTypeExtension.php
80+
81+
-
82+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
83+
count: 1
84+
path: src/Extensions/DoctrineResultDynamicReturnTypeExtension.php
85+
86+
-
87+
message: "#^Class Doctrine\\\\DBAL\\\\Statement not found\\.$#"
88+
count: 1
89+
path: src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php
90+
91+
-
92+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
93+
count: 1
94+
path: src/Extensions/PdoStatementColumnCountDynamicReturnTypeExtension.php
95+
96+
-
97+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
98+
count: 1
99+
path: src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php
100+
18101
-
19102
message: "#^Strict comparison using \\!\\=\\= between null and PHPStan\\\\Type\\\\Type will always evaluate to true\\.$#"
20103
count: 1
21104
path: src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php
22105

106+
-
107+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
108+
count: 1
109+
path: src/Extensions/PdoStatementFetchObjectDynamicReturnTypeExtension.php
110+
111+
-
112+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
113+
count: 1
114+
path: src/PdoReflection/PdoStatementObjectType.php
115+
116+
-
117+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
118+
count: 1
119+
path: src/PdoReflection/PdoStatementObjectType.php
120+
121+
-
122+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
123+
count: 1
124+
path: src/PdoReflection/PdoStatementReflection.php
125+
23126
-
24127
message: "#^Strict comparison using \\=\\=\\= between 'dibi' and 'dibi' will always evaluate to true\\.$#"
25128
count: 1
26129
path: src/QueryReflection/DbaApi.php
27130

28131
-
29-
message: "#^Return type \\(array\\<int, array\\{name\\: string, table\\?\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoPgSqlQueryReflector\\:\\:simulateQuery\\(\\) should be covariant with return type \\(array\\<int, array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: 0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\|2147483648\\}\\>\\|PDOException\\|null\\) of method staabm\\\\PHPStanDba\\\\QueryReflection\\\\BasePdoQueryReflector\\:\\:simulateQuery\\(\\)$#"
132+
message: """
133+
#^Call to deprecated method getConstantArrays\\(\\) of class PHPStan\\\\Type\\\\TypeUtils\\:
134+
Use PHPStan\\\\Type\\\\Type\\:\\:getConstantArrays\\(\\) instead and handle optional keys if necessary\\.$#
135+
"""
136+
count: 1
137+
path: src/QueryReflection/QueryReflection.php
138+
139+
-
140+
message: """
141+
#^Call to deprecated method getConstantStrings\\(\\) of class PHPStan\\\\Type\\\\TypeUtils\\:
142+
Use PHPStan\\\\Type\\\\Type\\:\\:getConstantStrings\\(\\) instead$#
143+
"""
30144
count: 1
31-
path: src/QueryReflection/PdoPgSqlQueryReflector.php
145+
path: src/QueryReflection/QueryReflection.php
146+
147+
-
148+
message: """
149+
#^Call to deprecated method resolvePreparedQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
150+
use resolvePreparedQueryStrings\\(\\) instead$#
151+
"""
152+
count: 1
153+
path: src/QueryReflection/QueryReflection.php
32154

33155
-
34156
message: "#^Casting to \\*NEVER\\* something that's already \\*NEVER\\*\\.$#"
35157
count: 1
36158
path: src/QueryReflection/QueryReflection.php
37159

38160
-
39-
message: "#^Instanceof between PHPStan\\\\Type\\\\Constant\\\\ConstantIntegerType and PHPStan\\\\Type\\\\Constant\\\\ConstantIntegerType will always evaluate to true\\.$#"
161+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
162+
count: 3
163+
path: src/QueryReflection/QueryReflection.php
164+
165+
-
166+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
40167
count: 1
41168
path: src/QueryReflection/QueryReflection.php
42169

@@ -45,6 +172,69 @@ parameters:
45172
count: 1
46173
path: src/QueryReflection/QueryReflection.php
47174

175+
-
176+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Accessory\\\\AccessoryType is error\\-prone and deprecated\\. Use methods on PHPStan\\\\Type\\\\Type instead\\.$#"
177+
count: 1
178+
path: src/QueryReflection/QuerySimulation.php
179+
180+
-
181+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ArrayType is error\\-prone and deprecated\\. Use Type\\:\\:isArray\\(\\) or Type\\:\\:getArrays\\(\\) instead\\.$#"
182+
count: 1
183+
path: src/QueryReflection/QuerySimulation.php
184+
185+
-
186+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
187+
count: 1
188+
path: src/QueryReflection/QuerySimulation.php
189+
190+
-
191+
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
192+
count: 2
193+
path: src/QueryReflection/QuerySimulation.php
194+
195+
-
196+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
197+
count: 2
198+
path: src/QueryReflection/QuerySimulation.php
199+
200+
-
201+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
202+
count: 1
203+
path: src/Rules/DoctrineKeyValueStyleRule.php
204+
205+
-
206+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
207+
count: 2
208+
path: src/Rules/DoctrineKeyValueStyleRule.php
209+
210+
-
211+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
212+
count: 1
213+
path: src/Rules/PdoStatementExecuteMethodRule.php
214+
215+
-
216+
message: """
217+
#^Call to deprecated method resolveQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
218+
use resolveQueryStrings\\(\\) instead$#
219+
"""
220+
count: 1
221+
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php
222+
223+
-
224+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
225+
count: 2
226+
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php
227+
228+
-
229+
message: "#^Doing instanceof PHPStan\\\\Type\\\\StringType is error\\-prone and deprecated\\. Use Type\\:\\:isString\\(\\) instead\\.$#"
230+
count: 1
231+
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php
232+
233+
-
234+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
235+
count: 1
236+
path: src/SchemaReflection/SchemaReflection.php
237+
48238
-
49239
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
50240
count: 2

src/SchemaReflection/SchemaReflection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace staabm\PHPStanDba\SchemaReflection;
66

7-
use PHPStan\ShouldNotHappenException;
87
use PHPStan\Type\Constant\ConstantArrayType;
9-
use PHPStan\Type\Constant\ConstantStringType;
108

119
final class SchemaReflection
1210
{
@@ -43,11 +41,9 @@ public function getTable(string $tableName): ?Table
4341
$valueTypes = $resultType->getValueTypes();
4442
$columns = [];
4543
foreach ($keyTypes as $i => $keyType) {
46-
if (! $keyType instanceof ConstantStringType) {
47-
throw new ShouldNotHappenException();
44+
foreach ($keyType->getConstantStrings() as $constantString) {
45+
$columns[] = new Column($constantString->getValue(), $valueTypes[$i]);
4846
}
49-
50-
$columns[] = new Column($keyType->getValue(), $valueTypes[$i]);
5147
}
5248

5349
return $this->tables[$tableName] = new Table($tableName, $columns);

src/SqlAst/StrCaseReturnTypeExtension.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,20 @@ public function getReturnType(FunctionCall $expression, QueryScope $scope): ?Typ
4242
return new NullType();
4343
}
4444

45-
if ($argType instanceof ConstantStringType) {
45+
$results = [];
46+
$constantStrings = $argType->getConstantStrings();
47+
foreach ($constantStrings as $constantString) {
4648
if (\in_array($expression->getFunction()->getName(), [BuiltInFunction::LOWER, BuiltInFunction::LCASE], true)) {
47-
return new ConstantStringType(strtolower($argType->getValue()));
49+
$results[] = new ConstantStringType(strtolower($constantString->getValue()));
50+
51+
continue;
4852
}
4953

50-
return new ConstantStringType(strtoupper($argType->getValue()));
54+
$results[] = new ConstantStringType(strtoupper($constantString->getValue()));
55+
}
56+
57+
if (count($results) > 0) {
58+
return TypeCombinator::union(...$results);
5159
}
5260

5361
if (TypeCombinator::containsNull($argType)) {

0 commit comments

Comments
 (0)