Updated Rector to commit d67342e4e23b577a259e2d2af0ed64461db9968b

d67342e4e2 Fix original quotes in PregReplaceEModifierRector (#5827)
This commit is contained in:
Tomas Votruba 2024-04-17 10:04:21 +00:00
parent b7b08c4396
commit 83bfbc18b8
3 changed files with 13 additions and 23 deletions

View File

@ -5,6 +5,7 @@ namespace Rector\Php55\Rector\FuncCall;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name; use PhpParser\Node\Name;
@ -89,13 +90,11 @@ CODE_SAMPLE
$firstArgument = $node->getArgs()[0]; $firstArgument = $node->getArgs()[0];
$firstArgumentValue = $firstArgument->value; $firstArgumentValue = $firstArgument->value;
$patternWithoutEExpr = $this->regexMatcher->resolvePatternExpressionWithoutEIfFound($firstArgumentValue); $patternWithoutEExpr = $this->regexMatcher->resolvePatternExpressionWithoutEIfFound($firstArgumentValue);
if ($patternWithoutEExpr === null) { if (!$patternWithoutEExpr instanceof Expr) {
return null; return null;
} }
/** @var Arg $secondArgument */ $secondArgument = $node->getArgs()[1];
$secondArgument = $node->args[1]; $anonymousFunction = $this->createAnonymousFunction($secondArgument);
$secondArgumentValue = $secondArgument->value;
$anonymousFunction = $this->anonymousFunctionFactory->createAnonymousFunctionFromExpr($secondArgumentValue);
if (!$anonymousFunction instanceof Closure) { if (!$anonymousFunction instanceof Closure) {
return null; return null;
} }
@ -104,4 +103,8 @@ CODE_SAMPLE
$secondArgument->value = $anonymousFunction; $secondArgument->value = $anonymousFunction;
return $node; return $node;
} }
private function createAnonymousFunction(Arg $arg) : ?Closure
{
return $this->anonymousFunctionFactory->createAnonymousFunctionFromExpr($arg->value);
}
} }

View File

@ -7,14 +7,8 @@ use RectorPrefix202404\Nette\Utils\Strings;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
use Rector\PhpParser\Node\Value\ValueResolver;
final class RegexMatcher final class RegexMatcher
{ {
/**
* @readonly
* @var \Rector\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
/** /**
* @var string * @var string
* @see https://regex101.com/r/Ok4wuE/1 * @see https://regex101.com/r/Ok4wuE/1
@ -30,20 +24,13 @@ final class RegexMatcher
* @see https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php * @see https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
*/ */
private const ALL_MODIFIERS_VALUES = ['i', 'm', 's', 'x', 'e', 'A', 'D', 'S', 'U', 'X', 'J', 'u']; private const ALL_MODIFIERS_VALUES = ['i', 'm', 's', 'x', 'e', 'A', 'D', 'S', 'U', 'X', 'J', 'u'];
public function __construct(ValueResolver $valueResolver)
{
$this->valueResolver = $valueResolver;
}
/** /**
* @return \PhpParser\Node\Expr\BinaryOp\Concat|\PhpParser\Node\Scalar\String_|null * @return \PhpParser\Node\Expr\BinaryOp\Concat|\PhpParser\Node\Scalar\String_|null
*/ */
public function resolvePatternExpressionWithoutEIfFound(Expr $expr) public function resolvePatternExpressionWithoutEIfFound(Expr $expr)
{ {
if ($expr instanceof String_) { if ($expr instanceof String_) {
$pattern = $this->valueResolver->getValue($expr); $pattern = $expr->value;
if (!\is_string($pattern)) {
return null;
}
$delimiter = $pattern[0]; $delimiter = $pattern[0];
switch ($delimiter) { switch ($delimiter) {
case '(': case '(':
@ -67,8 +54,8 @@ final class RegexMatcher
if (\strpos($modifiers, 'e') === \false) { if (\strpos($modifiers, 'e') === \false) {
return null; return null;
} }
$patternWithoutE = $this->createPatternWithoutE($pattern, $delimiter, $modifiers); $expr->value = $this->createPatternWithoutE($pattern, $delimiter, $modifiers);
return new String_($patternWithoutE); return $expr;
} }
if ($expr instanceof Concat) { if ($expr instanceof Concat) {
return $this->matchConcat($expr); return $this->matchConcat($expr);

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '7574abd469cbfe569dd47dd9ae9e6aa668a0cf1b'; public const PACKAGE_VERSION = 'd67342e4e23b577a259e2d2af0ed64461db9968b';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-04-17 16:27:51'; public const RELEASE_DATE = '2024-04-17 10:01:56';
/** /**
* @var int * @var int
*/ */