From c69f4f04ec67fbdefd9ecc6ea8f48345afe485bb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Mar 2024 09:04:40 +0700 Subject: [PATCH 1/3] [Scoper] Handle use nette/utils on php < 7.4 on 6th param on preg_replace_callback() --- scoper.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scoper.php b/scoper.php index a5f9080552b..3a8c46f261b 100644 --- a/scoper.php +++ b/scoper.php @@ -102,5 +102,23 @@ static function (string $filePath, string $prefix, string $content): string { return Unprefixer::unprefixQuoted($content, $prefix); }, + + static function (string $filePath, string $prefix, string $content): string { + if (! \str_ends_with($filePath, 'vendor/nette/utils/src/Utils/Strings.php')) { + return $content; + } + + return str_replace( + 'return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit, 0, $flags]);', + <<<'CODE_SAMPLE' +if (PHP_VERSION_ID < 70400) { + return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit]); +} + +return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit, 0, $flags]); +CODE_SAMPLE, + $content + ); + }, ], ]; From 2a80ac3e73871f3076b5cd4fc2425d69cb95ac4a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Mar 2024 09:05:47 +0700 Subject: [PATCH 2/3] doc --- scoper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scoper.php b/scoper.php index 3a8c46f261b..3b23afe0dcd 100644 --- a/scoper.php +++ b/scoper.php @@ -110,13 +110,13 @@ static function (string $filePath, string $prefix, string $content): string { return str_replace( 'return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit, 0, $flags]);', - <<<'CODE_SAMPLE' + <<<'CODE_REPLACE' if (PHP_VERSION_ID < 70400) { return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit]); } return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit, 0, $flags]); -CODE_SAMPLE, +CODE_REPLACE, $content ); }, From cef2425d9e275bb0d065e6d70cd1b745bc378e11 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 19 Mar 2024 09:06:09 +0700 Subject: [PATCH 3/3] doc --- scoper.php | 1 + 1 file changed, 1 insertion(+) diff --git a/scoper.php b/scoper.php index 3b23afe0dcd..6af8dc48ec9 100644 --- a/scoper.php +++ b/scoper.php @@ -108,6 +108,7 @@ static function (string $filePath, string $prefix, string $content): string { return $content; } + # see https://github.com/rectorphp/rector/issues/8564 return str_replace( 'return self::pcre(\'preg_replace_callback\', [$pattern, $replacement, $subject, $limit, 0, $flags]);', <<<'CODE_REPLACE'