Skip to content

Commit 416e02a

Browse files
committed
Fix PHPStan 2.x deprecations
1 parent 1477092 commit 416e02a

File tree

5 files changed

+129
-47
lines changed

5 files changed

+129
-47
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"php": "^7.4 || ^8.0",
88
"composer-runtime-api": "^2.0",
99
"composer/semver": "^3.2",
10-
"doctrine/dbal": "3.*",
1110
"phpstan/phpstan": "^1.9.4"
1211
},
1312
"require-dev": {

phpstan-baseline.neon

Lines changed: 118 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@ parameters:
55
count: 2
66
path: src/Analyzer/QueryPlanAnalyzerMysql.php
77

8-
-
9-
message: "#^Instanceof between mysqli_result\\<array\\<string, int\\<\\-128, 127\\>\\|string\\|null\\>\\> and mysqli_result will always evaluate to true\\.$#"
10-
count: 1
11-
path: src/DbSchema/SchemaHasherMysql.php
12-
13-
-
14-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
15-
count: 1
16-
path: src/DoctrineReflection/DoctrineReflection.php
17-
18-
-
19-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
20-
count: 1
21-
path: src/DoctrineReflection/DoctrineReflection.php
22-
238
-
249
message: """
2510
#^Call to deprecated method resolveQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
@@ -29,13 +14,13 @@ parameters:
2914
path: src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php
3015

3116
-
32-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
17+
message: "#^Cannot call method getConstantArrays\\(\\) on PHPStan\\\\Type\\\\Type\\|null\\.$#"
3318
count: 1
3419
path: src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php
3520

3621
-
37-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
38-
count: 2
22+
message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValueTypes\\(\\)\\.$#"
23+
count: 5
3924
path: src/Extensions/DibiConnectionFetchDynamicReturnTypeExtension.php
4025

4126
-
@@ -73,11 +58,66 @@ parameters:
7358
count: 1
7459
path: src/PdoReflection/PdoStatementReflection.php
7560

61+
-
62+
message: "#^Method staabm\\\\PHPStanDba\\\\PdoReflection\\\\PdoStatementReflection\\:\\:getClassRowType\\(\\) never returns null so it can be removed from the return type\\.$#"
63+
count: 1
64+
path: src/PdoReflection/PdoStatementReflection.php
65+
66+
-
67+
message: "#^Method staabm\\\\PHPStanDba\\\\PdoReflection\\\\PdoStatementReflection\\:\\:getFetchType\\(\\) never returns 1 so it can be removed from the return type\\.$#"
68+
count: 1
69+
path: src/PdoReflection/PdoStatementReflection.php
70+
71+
-
72+
message: "#^Method staabm\\\\PHPStanDba\\\\PdoReflection\\\\PdoStatementReflection\\:\\:getFetchType\\(\\) never returns 2 so it can be removed from the return type\\.$#"
73+
count: 1
74+
path: src/PdoReflection/PdoStatementReflection.php
75+
76+
-
77+
message: "#^Parameter \\#2 \\$flags of method staabm\\\\PHPStanDba\\\\TypeMapping\\\\TypeMapper\\:\\:mapToPHPStanType\\(\\) expects list\\<string\\>, array\\<int, string\\> given\\.$#"
78+
count: 2
79+
path: src/QueryReflection/BasePdoQueryReflector.php
80+
7681
-
7782
message: "#^Strict comparison using \\=\\=\\= between 'dibi' and 'dibi' will always evaluate to true\\.$#"
7883
count: 1
7984
path: src/QueryReflection/DbaApi.php
8085

86+
-
87+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\MysqliQueryReflector\\:\\:getDatasource\\(\\) never returns PDO so it can be removed from the return type\\.$#"
88+
count: 1
89+
path: src/QueryReflection/MysqliQueryReflector.php
90+
91+
-
92+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\MysqliQueryReflector\\:\\:getDatasource\\(\\) never returns null so it can be removed from the return type\\.$#"
93+
count: 1
94+
path: src/QueryReflection/MysqliQueryReflector.php
95+
96+
-
97+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoMysqlQueryReflector\\:\\:simulateQuery\\(\\) should return list\\<array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: \\-2147483648\\|0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\}\\>\\|PDOException\\|null but returns array\\<int\\<0, max\\>, array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: \\-2147483648\\|0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\}\\>\\|PDOException\\|null\\.$#"
98+
count: 1
99+
path: src/QueryReflection/PdoMysqlQueryReflector.php
100+
101+
-
102+
message: "#^Property staabm\\\\PHPStanDba\\\\QueryReflection\\\\BasePdoQueryReflector\\:\\:\\$cache \\(array\\<string, list\\<array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: \\-2147483648\\|0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\}\\>\\|PDOException\\|null\\>\\) does not accept non\\-empty\\-array\\<string, array\\<int\\<0, max\\>, array\\{name\\: string, table\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: \\-2147483648\\|0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824, native_type\\: string\\}\\>\\|PDOException\\|null\\>\\.$#"
103+
count: 1
104+
path: src/QueryReflection/PdoMysqlQueryReflector.php
105+
106+
-
107+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoPgSqlQueryReflector\\:\\:simulateQuery\\(\\) should return list\\<array\\{name\\: string, table\\?\\: string, native_type\\: string, len\\: int, flags\\: list\\<string\\>\\}\\>\\|PDOException\\|null but returns array\\<int\\<0, max\\>, array\\{name\\: string, table\\?\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: \\-2147483648\\|0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\}\\>\\|PDOException\\|null\\.$#"
108+
count: 1
109+
path: src/QueryReflection/PdoPgSqlQueryReflector.php
110+
111+
-
112+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\PdoPgSqlQueryReflector\\:\\:simulateQuery\\(\\) should return list\\<array\\{name\\: string, table\\?\\: string, native_type\\: string, len\\: int, flags\\: list\\<string\\>\\}\\>\\|PDOException\\|null but returns list\\<array\\{name\\: string, table\\: string, native_type\\: string, len\\: int, flags\\: array\\<int, string\\>, precision\\: int\\<0, max\\>, pdo_type\\: \\-2147483648\\|0\\|1\\|2\\|3\\|4\\|5\\|6\\|536870912\\|1073741824\\}\\>\\|PDOException\\|null\\.$#"
113+
count: 1
114+
path: src/QueryReflection/PdoPgSqlQueryReflector.php
115+
116+
-
117+
message: "#^PHPDoc tag @var with type array\\{column_default\\?\\: string, column_name\\: string, is_nullable\\: string\\} is not subtype of type array\\{COLUMN_NAME\\: string, COLUMN_DEFAULT\\: string\\|null, IS_NULLABLE\\: string\\}\\.$#"
118+
count: 1
119+
path: src/QueryReflection/PdoPgSqlQueryReflector.php
120+
81121
-
82122
message: """
83123
#^Call to deprecated method resolvePreparedQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
@@ -102,19 +142,14 @@ parameters:
102142
path: src/QueryReflection/QueryReflection.php
103143

104144
-
105-
message: "#^Strict comparison using \\=\\=\\= between null and null will always evaluate to true\\.$#"
145+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:\\:extractNamedPlaceholders\\(\\) should return list\\<string\\> but returns array\\<int\\<0, max\\>, string\\>\\.$#"
106146
count: 1
107147
path: src/QueryReflection/QueryReflection.php
108148

109149
-
110-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Accessory\\\\AccessoryType is error\\-prone and deprecated\\. Use methods on PHPStan\\\\Type\\\\Type instead\\.$#"
111-
count: 1
112-
path: src/QueryReflection/QuerySimulation.php
113-
114-
-
115-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ArrayType is error\\-prone and deprecated\\. Use Type\\:\\:isArray\\(\\) or Type\\:\\:getArrays\\(\\) instead\\.$#"
150+
message: "#^Strict comparison using \\=\\=\\= between null and null will always evaluate to true\\.$#"
116151
count: 1
117-
path: src/QueryReflection/QuerySimulation.php
152+
path: src/QueryReflection/QueryReflection.php
118153

119154
-
120155
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
@@ -123,7 +158,7 @@ parameters:
123158

124159
-
125160
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
126-
count: 2
161+
count: 1
127162
path: src/QueryReflection/QuerySimulation.php
128163

129164
-
@@ -132,20 +167,35 @@ parameters:
132167
path: src/QueryReflection/QuerySimulation.php
133168

134169
-
135-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
170+
message: "#^Method staabm\\\\PHPStanDba\\\\QueryReflection\\\\ReflectionCache\\:\\:readCachedRecords\\(\\) should return array\\<string, array\\{error\\?\\: staabm\\\\PHPStanDba\\\\Error\\|null, result\\?\\: array\\<1\\|2\\|3\\|4\\|5\\|6\\|7\\|8, PHPStan\\\\Type\\\\Type\\|null\\>\\}\\>\\|null but returns array\\.$#"
136171
count: 1
137-
path: src/Rules/DoctrineKeyValueStyleRule.php
172+
path: src/QueryReflection/ReflectionCache.php
138173

139174
-
140-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
141-
count: 2
175+
message: "#^Return type \\(array\\<PHPStan\\\\Rules\\\\RuleError\\>\\) of method staabm\\\\PHPStanDba\\\\Rules\\\\DoctrineKeyValueStyleRule\\:\\:processNode\\(\\) should be covariant with return type \\(list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\>\\) of method PHPStan\\\\Rules\\\\Rule\\<PhpParser\\\\Node\\\\Expr\\\\CallLike\\>\\:\\:processNode\\(\\)$#"
176+
count: 1
142177
path: src/Rules/DoctrineKeyValueStyleRule.php
143178

144179
-
145180
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
146181
count: 1
147182
path: src/Rules/PdoStatementExecuteMethodRule.php
148183

184+
-
185+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\PdoStatementExecuteMethodRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\<PHPStan\\\\Rules\\\\RuleError\\>\\.$#"
186+
count: 1
187+
path: src/Rules/PdoStatementExecuteMethodRule.php
188+
189+
-
190+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\QueryPlanAnalyzerRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\<PHPStan\\\\Rules\\\\RuleError\\>\\.$#"
191+
count: 1
192+
path: src/Rules/QueryPlanAnalyzerRule.php
193+
194+
-
195+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\QueryPlanAnalyzerRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\LineRuleError&PHPStan\\\\Rules\\\\TipRuleError\\}\\.$#"
196+
count: 1
197+
path: src/Rules/QueryPlanAnalyzerRule.php
198+
149199
-
150200
message: """
151201
#^Call to deprecated method resolveQueryString\\(\\) of class staabm\\\\PHPStanDba\\\\QueryReflection\\\\QueryReflection\\:
@@ -165,19 +215,44 @@ parameters:
165215
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php
166216

167217
-
168-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
218+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\SyntaxErrorInDibiPreparedStatementMethodRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\<PHPStan\\\\Rules\\\\RuleError\\>\\.$#"
169219
count: 1
170-
path: src/SchemaReflection/SchemaReflection.php
220+
path: src/Rules/SyntaxErrorInDibiPreparedStatementMethodRule.php
171221

172222
-
173-
message: "#^Call to an undefined method SqlFtw\\\\Sql\\\\Dml\\\\TableReference\\\\Join\\:\\:getCondition\\(\\)\\.$#"
174-
count: 2
175-
path: src/SqlAst/ParserInference.php
223+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\SyntaxErrorInPreparedStatementMethodRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\<PHPStan\\\\Rules\\\\RuleError\\>\\.$#"
224+
count: 1
225+
path: src/Rules/SyntaxErrorInPreparedStatementMethodRule.php
176226

177227
-
178-
message: "#^Call to an undefined method SqlFtw\\\\Sql\\\\Dml\\\\TableReference\\\\TableReferenceNode\\:\\:getTable\\(\\)\\.$#"
228+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\SyntaxErrorInQueryFunctionRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\LineRuleError&PHPStan\\\\Rules\\\\TipRuleError\\}\\.$#"
179229
count: 1
180-
path: src/SqlAst/ParserInference.php
230+
path: src/Rules/SyntaxErrorInQueryFunctionRule.php
231+
232+
-
233+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\SyntaxErrorInQueryFunctionRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\LineRuleError\\}\\.$#"
234+
count: 1
235+
path: src/Rules/SyntaxErrorInQueryFunctionRule.php
236+
237+
-
238+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\SyntaxErrorInQueryMethodRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\LineRuleError&PHPStan\\\\Rules\\\\TipRuleError\\}\\.$#"
239+
count: 1
240+
path: src/Rules/SyntaxErrorInQueryMethodRule.php
241+
242+
-
243+
message: "#^Method staabm\\\\PHPStanDba\\\\Rules\\\\SyntaxErrorInQueryMethodRule\\:\\:processNode\\(\\) should return list\\<PHPStan\\\\Rules\\\\IdentifierRuleError\\> but returns array\\{PHPStan\\\\Rules\\\\LineRuleError\\}\\.$#"
244+
count: 1
245+
path: src/Rules/SyntaxErrorInQueryMethodRule.php
246+
247+
-
248+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
249+
count: 1
250+
path: src/SchemaReflection/SchemaReflection.php
251+
252+
-
253+
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
254+
count: 1
255+
path: src/TypeMapping/MysqliTypeMapper.php
181256

182257
-
183258
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
@@ -188,3 +263,8 @@ parameters:
188263
message: "#^Only booleans are allowed in an if condition, int given\\.$#"
189264
count: 1
190265
path: src/TypeMapping/MysqliTypeMapper.php
266+
267+
-
268+
message: "#^Parameter \\#2 \\$subject of function preg_match expects string, mixed given\\.$#"
269+
count: 2
270+
path: src/TypeMapping/MysqliTypeMapper.php

src/DoctrineReflection/DoctrineReflection.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function reduceResultType(MethodReflection $methodReflection, Type $resul
4444
return $this->reduceResultType($methodReflection, $resultType->getRowType());
4545
}
4646

47-
$resultRowType = $resultType;
4847
$usedMethod = strtolower($methodReflection->getName());
4948

5049
switch ($usedMethod) {
@@ -73,7 +72,9 @@ public function reduceResultType(MethodReflection $methodReflection, Type $resul
7372
$fetchType = QueryReflector::FETCH_TYPE_BOTH;
7473
}
7574

76-
if (QueryReflector::FETCH_TYPE_BOTH !== $fetchType && $resultRowType instanceof ConstantArrayType) {
75+
$resultRowType = $resultType->getConstantArrays();
76+
if (QueryReflector::FETCH_TYPE_BOTH !== $fetchType && count($resultRowType) === 1) {
77+
$resultRowType = $resultRowType[0];
7778
$builder = ConstantArrayTypeBuilder::createEmpty();
7879

7980
$keyTypes = $resultRowType->getKeyTypes();
@@ -104,9 +105,9 @@ public function reduceResultType(MethodReflection $methodReflection, Type $resul
104105
return new ArrayType(IntegerRangeType::fromInterval(0, null), $valueTypes[$i]);
105106
}
106107

107-
if (QueryReflector::FETCH_TYPE_NUMERIC === $fetchType && $keyType instanceof ConstantIntegerType) {
108+
if (QueryReflector::FETCH_TYPE_NUMERIC === $fetchType && $keyType->isInteger()->yes()) {
108109
$builder->setOffsetValueType($keyType, $valueTypes[$i]);
109-
} elseif (QueryReflector::FETCH_TYPE_ASSOC === $fetchType && $keyType instanceof ConstantStringType) {
110+
} elseif (QueryReflector::FETCH_TYPE_ASSOC === $fetchType && $keyType->isString()->yes()) {
110111
$builder->setOffsetValueType($keyType, $valueTypes[$i]);
111112
}
112113
}

src/Extensions/DeployerRunMysqlQueryDynamicReturnTypeExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4444
return null;
4545
}
4646

47-
$resultType = $queryReflection->getResultType($queryString, QueryReflector::FETCH_TYPE_NUMERIC);
48-
if ($resultType instanceof ConstantArrayType) {
47+
$resultTypes = $queryReflection->getResultType($queryString, QueryReflector::FETCH_TYPE_NUMERIC)->getConstantArrays();
48+
if (count($resultTypes) === 1) {
49+
$resultType = $resultTypes[0];
50+
4951
$builder = ConstantArrayTypeBuilder::createEmpty();
5052
foreach ($resultType->getKeyTypes() as $keyType) {
5153
$builder->setOffsetValueType($keyType, new StringType());

src/PdoReflection/PdoStatementObjectType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ private function reduceBothType(Type $bothType, int $fetchType): Type
8080
$valueTypes = $bothType->getValueTypes();
8181

8282
foreach ($keyTypes as $i => $keyType) {
83-
if (QueryReflector::FETCH_TYPE_NUMERIC === $fetchType && $keyType instanceof ConstantIntegerType) {
83+
if (QueryReflector::FETCH_TYPE_NUMERIC === $fetchType && $keyType->isInteger()->yes()) {
8484
$builder->setOffsetValueType($keyType, $valueTypes[$i]);
85-
} elseif (QueryReflector::FETCH_TYPE_ASSOC === $fetchType && $keyType instanceof ConstantStringType) {
85+
} elseif (QueryReflector::FETCH_TYPE_ASSOC === $fetchType && $keyType->isString()->yes()) {
8686
$builder->setOffsetValueType($keyType, $valueTypes[$i]);
8787
}
8888
}

0 commit comments

Comments
 (0)