From 02b8774a434b1b71edd8824440ceac1e3e49ee2b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 7 Mar 2024 15:52:56 +0100 Subject: [PATCH] Update param-out annotations --- phpstan-baseline.neon | 29 +++++++++++++++++++++++++++-- phpstan.neon.dist | 1 + src/MatchAllResult.php | 2 +- src/MatchAllStrictGroupsResult.php | 2 +- src/Preg.php | 30 +++++++++++++++--------------- src/Regex.php | 4 ++-- 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cbd3cbf..ce485eb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\\\\)\\: string, \\(callable\\(array\\\\}\\>\\)\\: string\\)\\|\\(callable\\(array\\\\)\\: string\\) given\\.$#" + count: 2 + path: src/Preg.php + + - + message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAll\\(\\) expects array\\\\>, \\(512 is 1 \\? array\\\\> \\: \\(512 is 2 \\? list\\\\> \\: \\(512 is 256\\|257 \\? array\\\\> \\: \\(512 is 258 \\? list\\\\> \\: \\(512 is 512\\|513 \\? array\\\\> \\: \\(512 is 514 \\? list\\\\> \\: \\(512 is 770 \\? list\\\\> \\: array\\)\\)\\)\\)\\)\\)\\) given\\.$#" + count: 1 + path: src/Preg.php + + - + message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAllWithOffsets\\(\\) expects array\\\\}\\>\\>, \\(768 is 1 \\? array\\\\> \\: \\(768 is 2 \\? list\\\\> \\: \\(768 is 256\\|257 \\? array\\\\> \\: \\(768 is 258 \\? list\\\\> \\: \\(768 is 512\\|513 \\? array\\\\> \\: \\(768 is 514 \\? list\\\\> \\: \\(768 is 770 \\? list\\\\> \\: array\\)\\)\\)\\)\\)\\)\\) given\\.$#" + count: 1 + path: src/Preg.php + + - + message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchWithOffsets\\(\\) expects array\\\\}\\>, array\\ given\\.$#" + count: 1 + path: src/Preg.php + + - + message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:pregMatch\\(\\) expects array\\, \\(int is int \\? array\\\\|string\\>\\> \\: \\(int is int \\? array\\ \\: \\(int is int \\? array\\\\> \\: array\\\\)\\)\\) 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\\, array given\\.$#" + count: 1 + path: src/Preg.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 287c844..add4274 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -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 diff --git a/src/MatchAllResult.php b/src/MatchAllResult.php index 4310c53..b22b52d 100644 --- a/src/MatchAllResult.php +++ b/src/MatchAllResult.php @@ -35,7 +35,7 @@ final class MatchAllResult /** * @param 0|positive-int $count - * @param array> $matches + * @param array> $matches */ public function __construct(int $count, array $matches) { diff --git a/src/MatchAllStrictGroupsResult.php b/src/MatchAllStrictGroupsResult.php index 69dcd06..b7ec397 100644 --- a/src/MatchAllStrictGroupsResult.php +++ b/src/MatchAllStrictGroupsResult.php @@ -35,7 +35,7 @@ final class MatchAllStrictGroupsResult /** * @param 0|positive-int $count - * @param array> $matches + * @param array> $matches */ public function __construct(int $count, array $matches) { diff --git a/src/Preg.php b/src/Preg.php index 1afbbb4..aec6b13 100644 --- a/src/Preg.php +++ b/src/Preg.php @@ -20,7 +20,7 @@ class Preg /** * @param non-empty-string $pattern - * @param array $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * @return 0|1 * @@ -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 $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * @return 0|1 * @throws UnexpectedNullMatchException @@ -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 $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL and PREG_OFFSET_CAPTURE are always set, no other flags are supported * @return 0|1 * @@ -79,7 +79,7 @@ public static function matchWithOffsets(string $pattern, string $subject, ?array /** * @param non-empty-string $pattern - * @param array> $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * @return 0|positive-int * @@ -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> $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * @return 0|positive-int * @throws UnexpectedNullMatchException @@ -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> $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL and PREG_MATCH_OFFSET are always set, no other flags are supported * @return 0|positive-int * @@ -167,7 +167,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1 /** * @param string|string[] $pattern - * @param callable(array): string $replacement + * @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array}>): string) : callable(array): string) $replacement * @param string $subject * @param int $count Set by method * @param int-mask $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 } /** - * @param array): string> $pattern + * @param ($flags is PREG_OFFSET_CAPTURE ? (array}>): string>) : array): string>) $pattern * @param string $subject * @param int $count Set by method * @param int-mask $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 * Variant of match() which returns a bool instead of int * * @param non-empty-string $pattern - * @param array $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * * @param-out array $matches @@ -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 $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * @throws UnexpectedNullMatchException * @@ -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> $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * * @param-out array> $matches @@ -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> $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * * @param-out array> $matches @@ -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 $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * * @param-out array}> $matches @@ -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> $matches Set by method + * @param array $matches Set by method * @param int-mask $flags PREG_UNMATCHED_AS_NULL is always set, no other flags are supported * * @param-out array}>> $matches @@ -418,7 +418,7 @@ private static function enforceNonNullMatchAll(string $pattern, array $matches, /** * @param non-empty-string $pattern - * @param array $matches Set by method + * @param array $matches Set by method * @param int-mask $flags * @return 0|1|false * diff --git a/src/Regex.php b/src/Regex.php index e43c935..8c4158a 100644 --- a/src/Regex.php +++ b/src/Regex.php @@ -120,7 +120,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1 /** * @param string|string[] $pattern - * @param callable(array): string $replacement + * @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array}>): string) : callable(array): string) $replacement * @param string $subject * @param int-mask $flags PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+ */ @@ -132,7 +132,7 @@ public static function replaceCallback($pattern, callable $replacement, $subject } /** - * @param array): string> $pattern + * @param ($flags is PREG_OFFSET_CAPTURE ? (array}>): string>) : array): string>) $pattern * @param string $subject * @param int-mask $flags PREG_OFFSET_CAPTURE or PREG_UNMATCHED_AS_NULL, only available on PHP 7.4+ */