From 28fb502a83ad3f7a50b19d8d53ef3ff86c8f8104 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 15 Mar 2024 13:59:09 +0100 Subject: [PATCH 1/3] Fix php8.4 deprecations and add CI versions --- .github/workflows/continuous-integration.yml | 3 +++ .github/workflows/lint.yml | 2 +- .github/workflows/phpstan.yml | 2 +- src/Preg.php | 6 +++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e14ed32..dc841a4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -22,6 +22,9 @@ jobs: - "7.4" - "8.0" - "8.1" + - "8.2" + - "8.3" + - "8.4" steps: - name: "Checkout" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d42a52a..55e69c9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,7 +14,7 @@ jobs: matrix: php-version: - "7.2" - - "8.1" + - "8.3" steps: - name: "Checkout" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index fa2d5c1..93bea17 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -18,7 +18,7 @@ jobs: matrix: php-version: - "7.2" - - "8.1" + - "8.3" steps: - name: "Checkout" diff --git a/src/Preg.php b/src/Preg.php index aec6b13..6b5464e 100644 --- a/src/Preg.php +++ b/src/Preg.php @@ -147,7 +147,7 @@ public static function matchAllWithOffsets(string $pattern, string $subject, ?ar * * @param-out int<0, max> $count */ - public static function replace($pattern, $replacement, $subject, int $limit = -1, int &$count = null): string + public static function replace($pattern, $replacement, $subject, int $limit = -1, ?int &$count = null): string { if (!is_scalar($subject)) { if (is_array($subject)) { @@ -174,7 +174,7 @@ public static function replace($pattern, $replacement, $subject, int $limit = -1 * * @param-out int<0, max> $count */ - public static function replaceCallback($pattern, callable $replacement, $subject, int $limit = -1, int &$count = null, int $flags = 0): string + public static function replaceCallback($pattern, callable $replacement, $subject, int $limit = -1, ?int &$count = null, int $flags = 0): string { if (!is_scalar($subject)) { if (is_array($subject)) { @@ -204,7 +204,7 @@ public static function replaceCallback($pattern, callable $replacement, $subject * * @param-out int<0, max> $count */ - public static function replaceCallbackArray(array $pattern, $subject, int $limit = -1, int &$count = null, int $flags = 0): string + public static function replaceCallbackArray(array $pattern, $subject, int $limit = -1, ?int &$count = null, int $flags = 0): string { if (!is_scalar($subject)) { if (is_array($subject)) { From 3de930c85efd3a65436a1cffd6768d647e763f4d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 15 Mar 2024 14:28:12 +0100 Subject: [PATCH 2/3] Add conditional param-out to fix internal returns --- src/Preg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Preg.php b/src/Preg.php index 6b5464e..5794f26 100644 --- a/src/Preg.php +++ b/src/Preg.php @@ -422,7 +422,7 @@ private static function enforceNonNullMatchAll(string $pattern, array $matches, * @param int-mask $flags * @return 0|1|false * - * @param-out array $matches + * @param-out ($flags is PREG_OFFSET_CAPTURE ? array}> : array) $matches */ private static function pregMatch(string $pattern, string $subject, ?array &$matches = null, int $flags = 0, int $offset = 0) { From 540af382c97b83c628227d5f87cf56466d476191 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 19 Mar 2024 10:03:05 +0100 Subject: [PATCH 3/3] Fix phpstan baseline --- phpstan-baseline.neon | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ce485eb..cab5dde 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -16,12 +16,7 @@ parameters: 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\\.$#" + message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:matchAllWithOffsets\\(\\) expects array\\\\}\\>\\>, array given\\.$#" count: 1 path: src/Preg.php @@ -31,11 +26,6 @@ parameters: 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: src/Preg.php - - - - message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:pregMatch\\(\\) expects array\\, array given\\.$#" + message: "#^Parameter &\\$matches @param\\-out type of method Composer\\\\Pcre\\\\Preg\\:\\:pregMatch\\(\\) expects array\\\\}\\|string\\|null\\>, array given\\.$#" count: 1 path: src/Preg.php