Skip to content

Commit

Permalink
[Scoper] Handle use nette/utils on php < 7.4 on 6th param on preg_rep…
Browse files Browse the repository at this point in the history
…lace_callback() (#5738)

* [Scoper] Handle use nette/utils on php < 7.4 on 6th param on preg_replace_callback()

* doc

* doc
  • Loading branch information
samsonasik authored Mar 19, 2024
1 parent b052ed9 commit fd9e172
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,24 @@ 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;
}

# 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'
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_REPLACE,
$content
);
},
],
];

0 comments on commit fd9e172

Please sign in to comment.