diff --git a/rules-tests/Php73/Rector/FuncCall/RegexDashEscapeRector/Fixture/skip_three_backslash.php.inc b/rules-tests/Php73/Rector/FuncCall/RegexDashEscapeRector/Fixture/skip_three_backslash.php.inc new file mode 100644 index 000000000000..3afaea2a6bfe --- /dev/null +++ b/rules-tests/Php73/Rector/FuncCall/RegexDashEscapeRector/Fixture/skip_three_backslash.php.inc @@ -0,0 +1,11 @@ +=\/\\\,:.\-\s\+]+\)#", $text, $matches); + } +} diff --git a/rules/Downgrade72/Rector/FuncCall/DowngradeStreamIsattyRector.php b/rules/Downgrade72/Rector/FuncCall/DowngradeStreamIsattyRector.php index bed201834444..6210ece584c1 100644 --- a/rules/Downgrade72/Rector/FuncCall/DowngradeStreamIsattyRector.php +++ b/rules/Downgrade72/Rector/FuncCall/DowngradeStreamIsattyRector.php @@ -135,15 +135,15 @@ private function createIf(Expr $expr): If_ return $if; } - private function createClosure($node): Closure + private function createClosure(FuncCall $funcCall): Closure { - $if = $this->createIf($node->args[0]->value); + $if = $this->createIf($funcCall->args[0]->value); $function = new Closure(); $function->params[] = new Param(new Variable('stream')); $function->stmts[] = $if; - $posixIsatty = $this->nodeFactory->createFuncCall('posix_isatty', [$node->args[0]->value]); + $posixIsatty = $this->nodeFactory->createFuncCall('posix_isatty', [$funcCall->args[0]->value]); $function->stmts[] = new Return_(new ErrorSuppress($posixIsatty)); return $function; } diff --git a/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php b/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php index 921c977a07ac..39762c23c8d3 100644 --- a/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php +++ b/rules/Php73/Rector/FuncCall/RegexDashEscapeRector.php @@ -21,6 +21,15 @@ */ final class RegexDashEscapeRector extends AbstractRector { + + /** + * @var string + * @see https://regex101.com/r/iQbGgZ/1 + * + * Use {2} as detected only 2 after $this->regexPatternArgumentManipulator->matchCallArgumentWithRegexPattern() call + */ + private const THREE_BACKSLASH_FOR_ESCAPE_NEXT_REGEX = '#(?<=[^\\\\])\\\\{2}(?=[^\\\\])#'; + /** * @var string * @see https://regex101.com/r/YgVJFp/1 @@ -77,6 +86,10 @@ public function refactor(Node $node): ?Node } foreach ($regexArguments as $regexArgument) { + if (Strings::match($regexArgument->value, self::THREE_BACKSLASH_FOR_ESCAPE_NEXT_REGEX)) { + continue; + } + $this->escapeStringNode($regexArgument); }