Skip to content

Commit

Permalink
Update param-out annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 7, 2024
1 parent b439557 commit 02b8774
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
29 changes: 27 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ parameters:
path: src/Preg.php

-
message: "#^Offset 0 does not exist on string\\|null\\.$#"
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\\.$#"
count: 2
path: src/Preg.php

-
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\\.$#"
count: 1
path: src/Preg.php

-
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\\.$#"
count: 1
path: src/Preg.php

-
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\\.$#"
count: 1
path: src/Preg.php

-
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\\.$#"
count: 1
path: tests/PregTests/ReplaceCallbackTest.php
path: src/Preg.php

-
message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:pregMatch\\(\\) expects array\\<int\\|string, string\\|null\\>, array given\\.$#"
count: 1
path: src/Preg.php
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ parameters:
- tests/phpstan-locate-phpunit-autoloader.php

includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- phpstan-baseline.neon
2 changes: 1 addition & 1 deletion src/MatchAllResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class MatchAllResult

/**
* @param 0|positive-int $count
* @param array<int|string, array<string|null>> $matches
* @param array<int|string, list<string|null>> $matches
*/
public function __construct(int $count, array $matches)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MatchAllStrictGroupsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class MatchAllStrictGroupsResult

/**
* @param 0|positive-int $count
* @param array<array<string>> $matches
* @param array<list<string>> $matches
*/
public function __construct(int $count, array $matches)
{
Expand Down
30 changes: 15 additions & 15 deletions src/Preg.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Preg

/**
* @param non-empty-string $pattern
* @param array<string|null> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
* @return 0|1
*
Expand All @@ -42,7 +42,7 @@ public static function match(string $pattern, string $subject, ?array &$matches
* Variant of `match()` which outputs non-null matches (or throws)
*
* @param non-empty-string $pattern
* @param array<string> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
* @return 0|1
* @throws UnexpectedNullMatchException
Expand All @@ -61,7 +61,7 @@ public static function matchStrictGroups(string $pattern, string $subject, ?arra
* Runs preg_match with PREG_OFFSET_CAPTURE
*
* @param non-empty-string $pattern
* @param array<int|string, array{string|null, int}> $matches Set by method
* @param array<mixed> $matches Set by method
* @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
* @return 0|1
*
Expand All @@ -79,7 +79,7 @@ public static function matchWithOffsets(string $pattern, string $subject, ?array

/**
* @param non-empty-string $pattern
* @param array<int|string, list<string|null>> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
* @return 0|positive-int
*
Expand All @@ -102,7 +102,7 @@ public static function matchAll(string $pattern, string $subject, ?array &$match
* Variant of `match()` which outputs non-null matches (or throws)
*
* @param non-empty-string $pattern
* @param array<int|string, list<string|null>> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
* @return 0|positive-int
* @throws UnexpectedNullMatchException
Expand All @@ -121,7 +121,7 @@ public static function matchAllStrictGroups(string $pattern, string $subject, ?a
* Runs preg_match_all with PREG_OFFSET_CAPTURE
*
* @param non-empty-string $pattern
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
* @param array<mixed> $matches Set by method
* @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
* @return 0|positive-int
*
Expand Down Expand Up @@ -167,7 +167,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1

/**
* @param string|string[] $pattern
* @param callable(array<int|string, string|null>): string $replacement
* @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
* @param string $subject
* @param int $count Set by method
* @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+
Expand Down Expand Up @@ -197,7 +197,7 @@ public static function replaceCallback($pattern, callable $replacement, $subject
}

/**
* @param array<string, callable(array<int|string, string|null>): string> $pattern
* @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
* @param string $subject
* @param int $count Set by method
* @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+
Expand Down Expand Up @@ -281,7 +281,7 @@ public static function grep(string $pattern, array $array, int $flags = 0): arra
* Variant of match() which returns a bool instead of int
*
* @param non-empty-string $pattern
* @param array<string|null> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
*
* @param-out array<int|string, string|null> $matches
Expand All @@ -295,7 +295,7 @@ public static function isMatch(string $pattern, string $subject, ?array &$matche
* Variant of `isMatch()` which outputs non-null matches (or throws)
*
* @param non-empty-string $pattern
* @param array<string> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
* @throws UnexpectedNullMatchException
*
Expand All @@ -310,7 +310,7 @@ public static function isMatchStrictGroups(string $pattern, string $subject, ?ar
* Variant of matchAll() which returns a bool instead of int
*
* @param non-empty-string $pattern
* @param array<int|string, list<string|null>> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
*
* @param-out array<int|string, list<string|null>> $matches
Expand All @@ -324,7 +324,7 @@ public static function isMatchAll(string $pattern, string $subject, ?array &$mat
* Variant of `isMatchAll()` which outputs non-null matches (or throws)
*
* @param non-empty-string $pattern
* @param array<int|string, list<string>> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
*
* @param-out array<int|string, list<string>> $matches
Expand All @@ -340,7 +340,7 @@ public static function isMatchAllStrictGroups(string $pattern, string $subject,
* Runs preg_match with PREG_OFFSET_CAPTURE
*
* @param non-empty-string $pattern
* @param array<int|string, array{string|null, int}> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
*
* @param-out array<int|string, array{string|null, int<-1, max>}> $matches
Expand All @@ -356,7 +356,7 @@ public static function isMatchWithOffsets(string $pattern, string $subject, ?arr
* Runs preg_match_all with PREG_OFFSET_CAPTURE
*
* @param non-empty-string $pattern
* @param array<int|string, list<array{string|null, int}>> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL> $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported
*
* @param-out array<int|string, list<array{string|null, int<-1, max>}>> $matches
Expand Down Expand Up @@ -418,7 +418,7 @@ private static function enforceNonNullMatchAll(string $pattern, array $matches,

/**
* @param non-empty-string $pattern
* @param array<string|null> $matches Set by method
* @param array<mixed> $matches Set by method
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags
* @return 0|1|false
*
Expand Down
4 changes: 2 additions & 2 deletions src/Regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1

/**
* @param string|string[] $pattern
* @param callable(array<int|string, string|null>): string $replacement
* @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
* @param string $subject
* @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+
*/
Expand All @@ -132,7 +132,7 @@ public static function replaceCallback($pattern, callable $replacement, $subject
}

/**
* @param array<string, callable(array<int|string, string|null>): string> $pattern
* @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
* @param string $subject
* @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+
*/
Expand Down

0 comments on commit 02b8774

Please sign in to comment.