Skip to content

Commit 70c9343

Browse files
committed
clean up regex
1 parent 8eec399 commit 70c9343

2 files changed

Lines changed: 2 additions & 21 deletions

File tree

rules/Php72/NodeFactory/AnonymousFunctionFactory.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ public function create(
8282
public function createAnonymousFunctionFromExpr(Expr $expr): ?Closure
8383
{
8484
$stringValue = $this->inlineCodeParser->stringify($expr);
85-
$stringValue = $this->normalizeHexBackreferenceExpression($stringValue);
8685

8786
$phpCode = '<?php ' . $stringValue . ';';
8887
$contentStmts = $this->simplePhpParser->parseString($phpCode);
@@ -126,24 +125,6 @@ public function createAnonymousFunctionFromExpr(Expr $expr): ?Closure
126125
return $anonymousFunction;
127126
}
128127

129-
private function normalizeHexBackreferenceExpression(string $stringValue): string
130-
{
131-
// Only rewrite when the expression has no quotes, to avoid mutating string literals.
132-
if (str_contains($stringValue, "'") || str_contains($stringValue, '"')) {
133-
return $stringValue;
134-
}
135-
136-
return Strings::replace(
137-
$stringValue,
138-
'#0x(?<backreference>\\\d+|\$\d+)#',
139-
static function (array $match): string {
140-
$backreference = $match['backreference'];
141-
$number = ltrim($backreference, '\\$');
142-
return 'hexdec($matches[' . $number . '])';
143-
}
144-
);
145-
}
146-
147128
/**
148129
* @param Param[] $params
149130
* @return string[]

src/PhpParser/Parser/InlineCodeParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
private const string BACKREFERENCE_NO_DOUBLE_QUOTE_START_REGEX = '#(?<!")(?<backreference>\$\d+)#';
5454

5555
/**
56-
* @see https://regex101.com/r/8Dk7Qn/1
56+
* @see https://regex101.com/r/13mVVg/1
5757
*/
58-
private const string HEX_BACKREFERENCE_REGEX = '#0x(?<backreference>\\\d+|\$\d+)#';
58+
private const string HEX_BACKREFERENCE_REGEX = '#0x(?<backreference>\$\d+)#';
5959

6060
public function __construct(
6161
private BetterStandardPrinter $betterStandardPrinter,

0 commit comments

Comments
 (0)