Skip to content

Commit 5c4fc70

Browse files
committed
Merge branch '2.x'
2 parents c98c498 + ebb81df commit 5c4fc70

File tree

5 files changed

+66
-36
lines changed

5 files changed

+66
-36
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
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"

phpstan-baseline.neon

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,127 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Creating new PHPStan\\\\Reflection\\\\Native\\\\NativeParameterReflection is not covered by backward compatibility promise\\. The class might change in a minor PHPStan version\\.$#"
4+
message: '#^Creating new PHPStan\\Reflection\\Native\\NativeParameterReflection is not covered by backward compatibility promise\. The class might change in a minor PHPStan version\.$#'
5+
identifier: phpstanApi.constructor
56
count: 1
67
path: src/PHPStan/PregReplaceCallbackClosureTypeExtension.php
78

89
-
9-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, \\(callable\\(array\\<int\\|string, array\\{string\\|null, int\\<\\-1, max\\>\\}\\>\\)\\: string\\)\\|\\(callable\\(array\\<int\\|string, string\\|null\\>\\)\\: string\\) given\\.$#"
10+
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\.$#'
11+
identifier: argument.type
1012
count: 1
1113
path: src/Preg.php
1214

1315
-
14-
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\\.$#"
16+
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\.$#'
17+
identifier: paramOut.type
1518
count: 1
1619
path: src/Preg.php
1720

1821
-
19-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
22+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
23+
identifier: regexp.pattern
2024
count: 2
2125
path: tests/PregTests/GrepTest.php
2226

2327
-
24-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
28+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
29+
identifier: regexp.pattern
2530
count: 2
2631
path: tests/PregTests/IsMatchAllTest.php
2732

2833
-
29-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
34+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
35+
identifier: regexp.pattern
3036
count: 2
3137
path: tests/PregTests/IsMatchAllWithOffsetsTest.php
3238

3339
-
34-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
40+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
41+
identifier: regexp.pattern
3542
count: 2
3643
path: tests/PregTests/IsMatchTest.php
3744

3845
-
39-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
46+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
47+
identifier: regexp.pattern
4048
count: 2
4149
path: tests/PregTests/IsMatchWithOffsetsTest.php
4250

4351
-
44-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
52+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
53+
identifier: regexp.pattern
4554
count: 2
4655
path: tests/PregTests/MatchAllTest.php
4756

4857
-
49-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
58+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
59+
identifier: regexp.pattern
5060
count: 2
5161
path: tests/PregTests/MatchTest.php
5262

5363
-
54-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
64+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
65+
identifier: regexp.pattern
5566
count: 2
5667
path: tests/PregTests/ReplaceCallbackArrayTest.php
5768

5869
-
59-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
70+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
71+
identifier: regexp.pattern
6072
count: 2
6173
path: tests/PregTests/ReplaceCallbackTest.php
6274

6375
-
64-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
76+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
77+
identifier: regexp.pattern
6578
count: 2
6679
path: tests/PregTests/ReplaceTest.php
6780

6881
-
69-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
82+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
83+
identifier: regexp.pattern
7084
count: 2
7185
path: tests/PregTests/SplitTest.php
7286

7387
-
74-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
88+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
89+
identifier: regexp.pattern
7590
count: 2
7691
path: tests/PregTests/SplitWithOffsetsTest.php
7792

7893
-
79-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
94+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
95+
identifier: regexp.pattern
8096
count: 2
8197
path: tests/RegexTests/IsMatchTest.php
8298

8399
-
84-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
100+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
101+
identifier: regexp.pattern
85102
count: 2
86103
path: tests/RegexTests/MatchAllTest.php
87104

88105
-
89-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
106+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
107+
identifier: regexp.pattern
90108
count: 2
91109
path: tests/RegexTests/MatchTest.php
92110

93111
-
94-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
112+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
113+
identifier: regexp.pattern
95114
count: 2
96115
path: tests/RegexTests/ReplaceCallbackArrayTest.php
97116

98117
-
99-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
118+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
119+
identifier: regexp.pattern
100120
count: 2
101121
path: tests/RegexTests/ReplaceCallbackTest.php
102122

103123
-
104-
message: "#^Regex pattern is invalid\\: No ending matching delimiter '\\}' found$#"
124+
message: '#^Regex pattern is invalid\: No ending matching delimiter ''\}'' found$#'
125+
identifier: regexp.pattern
105126
count: 2
106127
path: tests/RegexTests/ReplaceTest.php

src/PHPStan/PregMatchTypeSpecifyingExtension.php

Lines changed: 16 additions & 0 deletions
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

src/PcreException.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ private static function pcreLastErrorMessage($code)
3939
return preg_last_error_msg();
4040
}
4141

42-
// older php versions did not set the code properly in all cases
43-
if (PHP_VERSION_ID < 70201 && $code === 0) {
44-
return 'UNDEFINED_ERROR';
45-
}
46-
4742
$constants = get_defined_constants(true);
4843
if (!isset($constants['pcre']) || !is_array($constants['pcre'])) {
4944
return 'UNDEFINED_ERROR';

tests/PHPStanTests/InvalidRegexPatternRuleTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,29 @@ protected function getRule(): \PHPStan\Rules\Rule
3131

3232
public function testRule(): void
3333
{
34-
$missing = PHP_VERSION_ID < 70300 ? ')' : 'closing parenthesis';
35-
3634
$this->analyse([__DIR__ . '/fixtures/invalid-patterns.php'], [
3735
[
38-
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
36+
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
3937
11,
4038
],
4139
[
42-
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
40+
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
4341
13,
4442
],
4543
[
46-
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
44+
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
4745
15,
4846
],
4947
[
50-
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
48+
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
5149
17,
5250
],
5351
[
54-
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
52+
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
5553
19,
5654
],
5755
[
58-
'Regex pattern is invalid: Compilation failed: missing '.$missing.' at offset 1',
56+
'Regex pattern is invalid: Compilation failed: missing closing parenthesis at offset 1',
5957
21,
6058
],
6159
]);

0 commit comments

Comments
 (0)