Skip to content

Commit 02b8774

Browse files
committed
Update param-out annotations
1 parent b439557 commit 02b8774

File tree

6 files changed

+47
-21
lines changed

6 files changed

+47
-21
lines changed

phpstan-baseline.neon

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ parameters:
1111
path: src/Preg.php
1212

1313
-
14-
message: "#^Offset 0 does not exist on string\\|null\\.$#"
14+
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\\.$#"
15+
count: 2
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\\>\\}\\>, array\\<int\\|string, string\\|null\\> given\\.$#"
30+
count: 1
31+
path: src/Preg.php
32+
33+
-
34+
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:pregMatch\\(\\) 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\\.$#"
1535
count: 1
16-
path: tests/PregTests/ReplaceCallbackTest.php
36+
path: src/Preg.php
37+
38+
-
39+
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:pregMatch\\(\\) expects array\\<int\\|string, string\\|null\\>, array given\\.$#"
40+
count: 1
41+
path: src/Preg.php

phpstan.neon.dist

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

1313
includes:
14+
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
1415
- vendor/phpstan/phpstan-strict-rules/rules.neon
1516
- 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: 15 additions & 15 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 or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+
@@ -197,7 +197,7 @@ public static function replaceCallback($pattern, callable $replacement, $subject
197197
}
198198

199199
/**
200-
* @param array<string, callable(array<int|string, string|null>): string> $pattern
200+
* @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
201201
* @param string $subject
202202
* @param int $count Set by method
203203
* @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+
@@ -281,7 +281,7 @@ public static function grep(string $pattern, array $array, int $flags = 0): arra
281281
* Variant of match() which returns a bool instead of int
282282
*
283283
* @param non-empty-string $pattern
284-
* @param array<string|null> $matches Set by method
284+
* @param array<mixed> $matches Set by method
285285
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
286286
*
287287
* @param-out array<int|string, string|null> $matches
@@ -295,7 +295,7 @@ public static function isMatch(string $pattern, string $subject, ?array &$matche
295295
* Variant of `isMatch()` which outputs non-null matches (or throws)
296296
*
297297
* @param non-empty-string $pattern
298-
* @param array<string> $matches Set by method
298+
* @param array<mixed> $matches Set by method
299299
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
300300
* @throws UnexpectedNullMatchException
301301
*
@@ -310,7 +310,7 @@ public static function isMatchStrictGroups(string $pattern, string $subject, ?ar
310310
* Variant of matchAll() which returns a bool instead of int
311311
*
312312
* @param non-empty-string $pattern
313-
* @param array<int|string, list<string|null>> $matches Set by method
313+
* @param array<mixed> $matches Set by method
314314
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
315315
*
316316
* @param-out array<int|string, list<string|null>> $matches
@@ -324,7 +324,7 @@ public static function isMatchAll(string $pattern, string $subject, ?array &$mat
324324
* Variant of `isMatchAll()` which outputs non-null matches (or throws)
325325
*
326326
* @param non-empty-string $pattern
327-
* @param array<int|string, list<string>> $matches Set by method
327+
* @param array<mixed> $matches Set by method
328328
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
329329
*
330330
* @param-out array<int|string, list<string>> $matches
@@ -340,7 +340,7 @@ public static function isMatchAllStrictGroups(string $pattern, string $subject,
340340
* Runs preg_match with PREG_OFFSET_CAPTURE
341341
*
342342
* @param non-empty-string $pattern
343-
* @param array<int|string, array{string|null, int}> $matches Set by method
343+
* @param array<mixed> $matches Set by method
344344
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
345345
*
346346
* @param-out array<int|string, array{string|null, int<-1, max>}> $matches
@@ -356,7 +356,7 @@ public static function isMatchWithOffsets(string $pattern, string $subject, ?arr
356356
* Runs preg_match_all with PREG_OFFSET_CAPTURE
357357
*
358358
* @param non-empty-string $pattern
359-
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
359+
* @param array<mixed> $matches Set by method
360360
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
361361
*
362362
* @param-out array<int|string, list<array{string|null, int<-1, max>}>> $matches
@@ -418,7 +418,7 @@ private static function enforceNonNullMatchAll(string $pattern, array $matches,
418418

419419
/**
420420
* @param non-empty-string $pattern
421-
* @param array<string|null> $matches Set by method
421+
* @param array<mixed> $matches Set by method
422422
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags
423423
* @return 0|1|false
424424
*

src/Regex.php

Lines changed: 2 additions & 2 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 or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+
126126
*/
@@ -132,7 +132,7 @@ public static function replaceCallback($pattern, callable $replacement, $subject
132132
}
133133

134134
/**
135-
* @param array<string, callable(array<int|string, string|null>): string> $pattern
135+
* @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
136136
* @param string $subject
137137
* @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+
138138
*/

0 commit comments

Comments
 (0)