Skip to content

Commit ebb81df

Browse files
Allow PHPStan 2.x
Co-authored-by: Jordi Boggiano <[email protected]>
1 parent 2227127 commit ebb81df

File tree

3 files changed

+70
-22
lines changed

3 files changed

+70
-22
lines changed

Diff for: composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^8 || ^9",
24-
"phpstan/phpstan": "^1.11.10",
25-
"phpstan/phpstan-strict-rules": "^1.1"
24+
"phpstan/phpstan": "^1.12 || ^2",
25+
"phpstan/phpstan-strict-rules": "^1 || ^2"
2626
},
2727
"conflict": {
2828
"phpstan/phpstan": "<1.11.10"

Diff for: phpstan-baseline.neon

+52-20
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ parameters:
1111
path: src/Preg.php
1212

1313
-
14-
message: "#^Creating new PHPStan\\\\Reflection\\\\Native\\\\NativeParameterReflection is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
14+
message: '#^Creating new PHPStan\\Reflection\\Native\\NativeParameterReflection is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
15+
identifier: phpstanApi.constructor
1516
count: 1
1617
path: src/PHPStan/PregReplaceCallbackClosureTypeExtension.php
1718

@@ -20,102 +21,133 @@ parameters:
2021
count: 2
2122
path: src/Preg.php
2223

24+
-
25+
message: '#^Parameter \#2 \$callback of function preg_replace_callback expects callable\(array\<string\>\)\: string, \(callable\(array\<int\|string, array\{string\|null, int\<\-1, max\>\}\>\)\: string\)\|\(callable\(array\<int\|string, string\|null\>\)\: string\) given\.$#'
26+
identifier: argument.type
27+
count: 2
28+
path: src/Preg.php
29+
2330
-
2431
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAllWithOffsets\\(\\) expects array\\<int\\|string, list\\<array\\{string\\|null, int\\<\\-1, max\\>\\}\\>\\>, array given\\.$#"
2532
count: 1
2633
path: src/Preg.php
2734

2835
-
29-
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchWithOffsets\\(\\) expects array\\<int\\|string, array\\{string\\|null, int\\<\\-1, max\\>\\}\\>, array\\<int\\|string, string\\|null\\> given\\.$#"
36+
message: '#^Parameter &\$matches @param\-out type of method Composer\\Pcre\\Preg\:\:matchAllWithOffsets\(\) expects array\<int\|string, list\<array\{string\|null, int\<\-1, max\>\}\>\>, array\<mixed\> given\.$#'
37+
identifier: paramOut.type
38+
count: 1
39+
path: src/Preg.php
40+
41+
-
42+
message: '#^Parameter &\$matches @param\-out type of method Composer\\Pcre\\Preg\:\:matchWithOffsets\(\) expects array\<int\|string, array\{string\|null, int\<\-1, max\>\}\>, array\<int\|string, string\|null\> given\.$#'
43+
identifier: paramOut.type
3044
count: 1
3145
path: src/Preg.php
3246

3347
-
34-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
48+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
49+
identifier: regexp.pattern
3550
count: 2
3651
path: tests/PregTests/GrepTest.php
3752

3853
-
39-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
54+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
55+
identifier: regexp.pattern
4056
count: 2
4157
path: tests/PregTests/IsMatchAllTest.php
4258

4359
-
44-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
60+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
61+
identifier: regexp.pattern
4562
count: 2
4663
path: tests/PregTests/IsMatchAllWithOffsetsTest.php
4764

4865
-
49-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
66+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
67+
identifier: regexp.pattern
5068
count: 2
5169
path: tests/PregTests/IsMatchTest.php
5270

5371
-
54-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
72+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
73+
identifier: regexp.pattern
5574
count: 2
5675
path: tests/PregTests/IsMatchWithOffsetsTest.php
5776

5877
-
59-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
78+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
79+
identifier: regexp.pattern
6080
count: 2
6181
path: tests/PregTests/MatchAllTest.php
6282

6383
-
64-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
84+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
85+
identifier: regexp.pattern
6586
count: 2
6687
path: tests/PregTests/MatchTest.php
6788

6889
-
69-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
90+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
91+
identifier: regexp.pattern
7092
count: 2
7193
path: tests/PregTests/ReplaceCallbackArrayTest.php
7294

7395
-
74-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
96+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
97+
identifier: regexp.pattern
7598
count: 2
7699
path: tests/PregTests/ReplaceCallbackTest.php
77100

78101
-
79-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
102+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
103+
identifier: regexp.pattern
80104
count: 2
81105
path: tests/PregTests/ReplaceTest.php
82106

83107
-
84-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
108+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
109+
identifier: regexp.pattern
85110
count: 2
86111
path: tests/PregTests/SplitTest.php
87112

88113
-
89-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
114+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
115+
identifier: regexp.pattern
90116
count: 2
91117
path: tests/PregTests/SplitWithOffsetsTest.php
92118

93119
-
94-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
120+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
121+
identifier: regexp.pattern
95122
count: 2
96123
path: tests/RegexTests/IsMatchTest.php
97124

98125
-
99-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
126+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
127+
identifier: regexp.pattern
100128
count: 2
101129
path: tests/RegexTests/MatchAllTest.php
102130

103131
-
104-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
132+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
133+
identifier: regexp.pattern
105134
count: 2
106135
path: tests/RegexTests/MatchTest.php
107136

108137
-
109-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
138+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
139+
identifier: regexp.pattern
110140
count: 2
111141
path: tests/RegexTests/ReplaceCallbackArrayTest.php
112142

113143
-
114-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
144+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
145+
identifier: regexp.pattern
115146
count: 2
116147
path: tests/RegexTests/ReplaceCallbackTest.php
117148

118149
-
119-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
150+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
151+
identifier: regexp.pattern
120152
count: 2
121153
path: tests/RegexTests/ReplaceTest.php

Diff for: src/PHPStan/PregMatchTypeSpecifyingExtension.php

+16
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,26 @@ public function specifyTypes(MethodReflection $methodReflection, StaticCall $nod
9393
$context = $context->negate();
9494
}
9595

96+
// @phpstan-ignore function.alreadyNarrowedType, function.impossibleType
97+
if (method_exists('PHPStan\Analyser\SpecifiedTypes', 'setRootExpr')) {
98+
// @phpstan-ignore method.notFound
99+
$typeSpecifier = $this->typeSpecifier->create(
100+
$matchesArg->value,
101+
$matchedType,
102+
$context,
103+
// @phpstan-ignore argument.type
104+
$scope
105+
)->setRootExpr($node);
106+
107+
return $overwrite ? $typeSpecifier->setAlwaysOverwriteTypes() : $typeSpecifier;
108+
}
109+
110+
// @phpstan-ignore arguments.count
96111
return $this->typeSpecifier->create(
97112
$matchesArg->value,
98113
$matchedType,
99114
$context,
115+
// @phpstan-ignore argument.type
100116
$overwrite,
101117
$scope,
102118
$node

0 commit comments

Comments
 (0)