Skip to content

Commit 7539e8f

Browse files
committed
Merge branch '2.x'
2 parents 0010430 + 02b8774 commit 7539e8f

File tree

6 files changed

+50
-24
lines changed

6 files changed

+50
-24
lines changed

phpstan-baseline.neon

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Offset 0 does not exist on string\\|null\\.$#"
4+
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\\.$#"
55
count: 1
6-
path: tests/PregTests/ReplaceCallbackTest.php
6+
path: src/Preg.php
7+
8+
-
9+
message: "#^Parameter \\#2 \\$matches of static method Composer\\\\Pcre\\\\Preg\\:\\:enforceNonNullMatches\\(\\) expects array\\<int\\|string, string\\|null\\>, array\\<int\\|string, array\\<int, int\\|string\\|null\\>\\|string\\|null\\> given\\.$#"
10+
count: 1
11+
path: src/Preg.php
12+
13+
-
14+
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:match\\(\\) expects array\\<int\\|string, string\\|null\\>, \\(int is int \\? array\\<array\\<int, int\\<\\-1, max\\>\\|string\\>\\> \\: \\(int is int \\? array\\<string\\|null\\> \\: \\(int is int \\? array\\<array\\<int, int\\|string\\|null\\>\\> \\: array\\<string\\>\\)\\)\\) given\\.$#"
15+
count: 1
16+
path: src/Preg.php
17+
18+
-
19+
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAll\\(\\) expects array\\<int\\|string, list\\<string\\|null\\>\\>, \\(512 is 1 \\? array\\<list\\<string\\>\\> \\: \\(512 is 2 \\? list\\<array\\<string\\>\\> \\: \\(512 is 256\\|257 \\? array\\<list\\<array\\{string, int\\}\\>\\> \\: \\(512 is 258 \\? list\\<array\\<array\\{string, int\\}\\>\\> \\: \\(512 is 512\\|513 \\? array\\<list\\<string\\|null\\>\\> \\: \\(512 is 514 \\? list\\<array\\<string\\|null\\>\\> \\: \\(512 is 770 \\? list\\<array\\<array\\{string\\|null, int\\}\\>\\> \\: array\\)\\)\\)\\)\\)\\)\\) given\\.$#"
20+
count: 1
21+
path: src/Preg.php
22+
23+
-
24+
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAllWithOffsets\\(\\) expects array\\<int\\|string, list\\<array\\{string\\|null, int\\<\\-1, max\\>\\}\\>\\>, \\(768 is 1 \\? array\\<list\\<string\\>\\> \\: \\(768 is 2 \\? list\\<array\\<string\\>\\> \\: \\(768 is 256\\|257 \\? array\\<list\\<array\\{string, int\\}\\>\\> \\: \\(768 is 258 \\? list\\<array\\<array\\{string, int\\}\\>\\> \\: \\(768 is 512\\|513 \\? array\\<list\\<string\\|null\\>\\> \\: \\(768 is 514 \\? list\\<array\\<string\\|null\\>\\> \\: \\(768 is 770 \\? list\\<array\\<array\\{string\\|null, int\\}\\>\\> \\: array\\)\\)\\)\\)\\)\\)\\) given\\.$#"
25+
count: 1
26+
path: src/Preg.php
27+
28+
-
29+
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchWithOffsets\\(\\) expects array\\<int\\|string, array\\{string\\|null, int\\<\\-1, max\\>\\}\\>, \\(768 is 256 \\? array\\<array\\{string, int\\<\\-1, max\\>\\}\\> \\: \\(768 is 512 \\? array\\<string\\|null\\> \\: \\(768 is 768 \\? array\\<array\\{null, \\-1\\}\\|array\\{string, int\\<0, max\\>\\}\\> \\: array\\<string\\>\\)\\)\\) given\\.$#"
30+
count: 1
31+
path: src/Preg.php

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ parameters:
1010
- tests/phpstan-locate-phpunit-autoloader.php
1111

1212
includes:
13+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
1314
- vendor/phpstan/phpstan-strict-rules/rules.neon
1415
- phpstan-baseline.neon

src/MatchAllResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class MatchAllResult
3535

3636
/**
3737
* @param 0|positive-int $count
38-
* @param array<int|string, array<string|null>> $matches
38+
* @param array<int|string, list<string|null>> $matches
3939
*/
4040
public function __construct(int $count, array $matches)
4141
{

src/MatchAllStrictGroupsResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class MatchAllStrictGroupsResult
3535

3636
/**
3737
* @param 0|positive-int $count
38-
* @param array<array<string>> $matches
38+
* @param array<list<string>> $matches
3939
*/
4040
public function __construct(int $count, array $matches)
4141
{

src/Preg.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Preg
2020

2121
/**
2222
* @param non-empty-string $pattern
23-
* @param array<string|null> $matches Set by method
23+
* @param array<mixed> $matches Set by method
2424
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
2525
* @return 0|1
2626
*
@@ -42,7 +42,7 @@ public static function match(string $pattern, string $subject, ?array &$matches
4242
* Variant of `match()` which outputs non-null matches (or throws)
4343
*
4444
* @param non-empty-string $pattern
45-
* @param array<string> $matches Set by method
45+
* @param array<mixed> $matches Set by method
4646
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
4747
* @return 0|1
4848
* @throws UnexpectedNullMatchException
@@ -61,7 +61,7 @@ public static function matchStrictGroups(string $pattern, string $subject, ?arra
6161
* Runs preg_match with PREG_OFFSET_CAPTURE
6262
*
6363
* @param non-empty-string $pattern
64-
* @param array<int|string, array{string|null, int}> $matches Set by method
64+
* @param array<mixed> $matches Set by method
6565
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_UNMATCHED_AS_NULL and PREG_OFFSET_CAPTURE are always set, no other flags are supported
6666
* @return 0|1
6767
*
@@ -79,7 +79,7 @@ public static function matchWithOffsets(string $pattern, string $subject, ?array
7979

8080
/**
8181
* @param non-empty-string $pattern
82-
* @param array<int|string, list<string|null>> $matches Set by method
82+
* @param array<mixed> $matches Set by method
8383
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
8484
* @return 0|positive-int
8585
*
@@ -102,7 +102,7 @@ public static function matchAll(string $pattern, string $subject, ?array &$match
102102
* Variant of `match()` which outputs non-null matches (or throws)
103103
*
104104
* @param non-empty-string $pattern
105-
* @param array<int|string, list<string|null>> $matches Set by method
105+
* @param array<mixed> $matches Set by method
106106
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
107107
* @return 0|positive-int
108108
* @throws UnexpectedNullMatchException
@@ -121,7 +121,7 @@ public static function matchAllStrictGroups(string $pattern, string $subject, ?a
121121
* Runs preg_match_all with PREG_OFFSET_CAPTURE
122122
*
123123
* @param non-empty-string $pattern
124-
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
124+
* @param array<mixed> $matches Set by method
125125
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_UNMATCHED_AS_NULL and PREG_MATCH_OFFSET are always set, no other flags are supported
126126
* @return 0|positive-int
127127
*
@@ -167,7 +167,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1
167167

168168
/**
169169
* @param string|string[] $pattern
170-
* @param callable(array<int|string, string|null>): string $replacement
170+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string|null, int<-1, max>}>): string) : callable(array<int|string, string|null>): string) $replacement
171171
* @param string $subject
172172
* @param int $count Set by method
173173
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
@@ -196,10 +196,10 @@ public static function replaceCallback($pattern, callable $replacement, $subject
196196
* Variant of `replaceCallback()` which outputs non-null matches (or throws)
197197
*
198198
* @param string $pattern
199-
* @param callable(array<int|string, string>): string $replacement
199+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string, int<0, max>}>): string) : callable(array<int|string, string>): string) $replacement
200200
* @param string $subject
201201
* @param int $count Set by method
202-
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+
202+
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
203203
*
204204
* @param-out int<0, max> $count
205205
*/
@@ -211,7 +211,7 @@ public static function replaceCallbackStrictGroups(string $pattern, callable $re
211211
}
212212

213213
/**
214-
* @param array<string, callable(array<int|string, string|null>): string> $pattern
214+
* @param ($flags is PREG_OFFSET_CAPTURE ? (array<string, callable(array<int|string, array{string|null, int<-1, max>}>): string>) : array<string, callable(array<int|string, string|null>): string>) $pattern
215215
* @param string $subject
216216
* @param int $count Set by method
217217
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
@@ -291,7 +291,7 @@ public static function grep(string $pattern, array $array, int $flags = 0): arra
291291
* Variant of match() which returns a bool instead of int
292292
*
293293
* @param non-empty-string $pattern
294-
* @param array<string|null> $matches Set by method
294+
* @param array<mixed> $matches Set by method
295295
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
296296
*
297297
* @param-out array<int|string, string|null> $matches
@@ -305,7 +305,7 @@ public static function isMatch(string $pattern, string $subject, ?array &$matche
305305
* Variant of `isMatch()` which outputs non-null matches (or throws)
306306
*
307307
* @param non-empty-string $pattern
308-
* @param array<string> $matches Set by method
308+
* @param array<mixed> $matches Set by method
309309
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
310310
* @throws UnexpectedNullMatchException
311311
*
@@ -320,7 +320,7 @@ public static function isMatchStrictGroups(string $pattern, string $subject, ?ar
320320
* Variant of matchAll() which returns a bool instead of int
321321
*
322322
* @param non-empty-string $pattern
323-
* @param array<int|string, list<string|null>> $matches Set by method
323+
* @param array<mixed> $matches Set by method
324324
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
325325
*
326326
* @param-out array<int|string, list<string|null>> $matches
@@ -334,7 +334,7 @@ public static function isMatchAll(string $pattern, string $subject, ?array &$mat
334334
* Variant of `isMatchAll()` which outputs non-null matches (or throws)
335335
*
336336
* @param non-empty-string $pattern
337-
* @param array<int|string, list<string>> $matches Set by method
337+
* @param array<mixed> $matches Set by method
338338
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
339339
*
340340
* @param-out array<int|string, list<string>> $matches
@@ -350,7 +350,7 @@ public static function isMatchAllStrictGroups(string $pattern, string $subject,
350350
* Runs preg_match with PREG_OFFSET_CAPTURE
351351
*
352352
* @param non-empty-string $pattern
353-
* @param array<int|string, array{string|null, int}> $matches Set by method
353+
* @param array<mixed> $matches Set by method
354354
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
355355
*
356356
* @param-out array<int|string, array{string|null, int<-1, max>}> $matches
@@ -366,7 +366,7 @@ public static function isMatchWithOffsets(string $pattern, string $subject, ?arr
366366
* Runs preg_match_all with PREG_OFFSET_CAPTURE
367367
*
368368
* @param non-empty-string $pattern
369-
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
369+
* @param array<mixed> $matches Set by method
370370
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
371371
*
372372
* @param-out array<int|string, list<array{string|null, int<-1, max>}>> $matches

src/Regex.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1
120120

121121
/**
122122
* @param string|string[] $pattern
123-
* @param callable(array<int|string, string|null>): string $replacement
123+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string|null, int<-1, max>}>): string) : callable(array<int|string, string|null>): string) $replacement
124124
* @param string $subject
125125
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
126126
*/
@@ -135,9 +135,9 @@ public static function replaceCallback($pattern, callable $replacement, $subject
135135
* Variant of `replaceCallback()` which outputs non-null matches (or throws)
136136
*
137137
* @param string $pattern
138-
* @param callable(array<int|string, string>): string $replacement
138+
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string, int<0, max>}>): string) : callable(array<int|string, string>): string) $replacement
139139
* @param string $subject
140-
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+
140+
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
141141
*/
142142
public static function replaceCallbackStrictGroups($pattern, callable $replacement, $subject, int $limit = -1, int $flags = 0): ReplaceResult
143143
{
@@ -147,7 +147,7 @@ public static function replaceCallbackStrictGroups($pattern, callable $replaceme
147147
}
148148

149149
/**
150-
* @param array<string, callable(array<int|string, string|null>): string> $pattern
150+
* @param ($flags is PREG_OFFSET_CAPTURE ? (array<string, callable(array<int|string, array{string|null, int<-1, max>}>): string>) : array<string, callable(array<int|string, string|null>): string>) $pattern
151151
* @param string $subject
152152
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
153153
*/

0 commit comments

Comments
 (0)