Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 7, 2024
2 parents 0010430 + 02b8774 commit 7539e8f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 24 deletions.
29 changes: 27 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
parameters:
ignoreErrors:
-
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: 1
path: tests/PregTests/ReplaceCallbackTest.php
path: src/Preg.php

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

-
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\\.$#"
count: 1
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\\>\\}\\>, \\(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\\.$#"
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 @@ -10,5 +10,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
32 changes: 16 additions & 16 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 is supported, PREG_UNMATCHED_AS_NULL is always set
Expand Down Expand Up @@ -196,10 +196,10 @@ public static function replaceCallback($pattern, callable $replacement, $subject
* Variant of `replaceCallback()` which outputs non-null matches (or throws)
*
* @param string $pattern
* @param callable(array<int|string, string>): string $replacement
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string, int<0, max>}>): string) : callable(array<int|string, string>): 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+
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
*
* @param-out int<0, max> $count
*/
Expand All @@ -211,7 +211,7 @@ public static function replaceCallbackStrictGroups(string $pattern, callable $re
}

/**
* @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 is supported, PREG_UNMATCHED_AS_NULL is always set
Expand Down Expand Up @@ -291,7 +291,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 @@ -305,7 +305,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 @@ -320,7 +320,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 @@ -334,7 +334,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 @@ -350,7 +350,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 @@ -366,7 +366,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
8 changes: 4 additions & 4 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 is supported, PREG_UNMATCHED_AS_NULL is always set
*/
Expand All @@ -135,9 +135,9 @@ public static function replaceCallback($pattern, callable $replacement, $subject
* Variant of `replaceCallback()` which outputs non-null matches (or throws)
*
* @param string $pattern
* @param callable(array<int|string, string>): string $replacement
* @param ($flags is PREG_OFFSET_CAPTURE ? (callable(array<int|string, array{string, int<0, max>}>): string) : callable(array<int|string, string>): 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+
* @param int-mask<PREG_UNMATCHED_AS_NULL|PREG_OFFSET_CAPTURE> $flags PREG_OFFSET_CAPTURE is supported, PREG_UNMATCHED_AS_NULL is always set
*/
public static function replaceCallbackStrictGroups($pattern, callable $replacement, $subject, int $limit = -1, int $flags = 0): ReplaceResult
{
Expand All @@ -147,7 +147,7 @@ public static function replaceCallbackStrictGroups($pattern, callable $replaceme
}

/**
* @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 is supported, PREG_UNMATCHED_AS_NULL is always set
*/
Expand Down

0 comments on commit 7539e8f

Please sign in to comment.