Updated Rector to commit de31e6f73765bef8a7285a00114037c07712add7

de31e6f737 [Naming] Allow rename variable in multiple statements on RenameVariableToMatchMethodCallReturnTypeRector (#5963)
This commit is contained in:
Tomas Votruba 2024-06-11 23:11:24 +00:00
parent 5b56f97fec
commit 97b31838f3
9 changed files with 25 additions and 21 deletions

View File

@ -60,8 +60,8 @@ CODE_SAMPLE
if (!$firstAssign->expr instanceof Assign) {
return null;
}
$lastAssignValue = $this->resolveLastAssignExpr($firstAssign);
$collectExpressions = $this->collectExpressions($firstAssign, $lastAssignValue);
$expr = $this->resolveLastAssignExpr($firstAssign);
$collectExpressions = $this->collectExpressions($firstAssign, $expr);
if ($collectExpressions === []) {
return null;
}

View File

@ -136,6 +136,7 @@ CODE_SAMPLE
if ($node->stmts === null) {
return null;
}
$hasChanged = \false;
foreach ($node->stmts as $stmt) {
if (!$stmt instanceof Expression) {
continue;
@ -146,7 +147,7 @@ CODE_SAMPLE
$assign = $stmt->expr;
$variableAndCallAssign = $this->variableAndCallAssignMatcher->match($assign, $node);
if (!$variableAndCallAssign instanceof VariableAndCallAssign) {
return null;
continue;
}
$call = $variableAndCallAssign->getCall();
$expectedName = $this->expectedNameResolver->resolveForCall($call);
@ -160,6 +161,9 @@ CODE_SAMPLE
continue;
}
$this->renameVariable($variableAndCallAssign, $expectedName, $stmt);
$hasChanged = \true;
}
if ($hasChanged) {
return $node;
}
return null;

View File

@ -108,8 +108,8 @@ final class SubstrMatchAndRefactor implements StrStartWithMatchAndRefactorInterf
if (!$this->valueResolver->isValue($secondArg->value, 0)) {
return \false;
}
$hardcodedStringNeedle = $strStartsWith->getNeedleExpr();
if (!$hardcodedStringNeedle instanceof String_) {
$expr = $strStartsWith->getNeedleExpr();
if (!$expr instanceof String_) {
return \false;
}
if (\count($substrFuncCall->getArgs()) < 3) {
@ -119,6 +119,6 @@ final class SubstrMatchAndRefactor implements StrStartWithMatchAndRefactorInterf
if (!$lNumberLength instanceof LNumber) {
return \false;
}
return $lNumberLength->value === \strlen($hardcodedStringNeedle->value);
return $lNumberLength->value === \strlen($expr->value);
}
}

View File

@ -132,8 +132,8 @@ CODE_SAMPLE
if ($this->shouldOmitEnumCase($enumCaseName)) {
return null;
}
$enumConstFetch = $this->nodeFactory->createClassConstFetch($className, $enumCaseName);
return new PropertyFetch($enumConstFetch, 'value');
$classConstFetch = $this->nodeFactory->createClassConstFetch($className, $enumCaseName);
return new PropertyFetch($classConstFetch, 'value');
}
private function refactorEqualsMethodCall(MethodCall $methodCall) : ?Identical
{

View File

@ -103,8 +103,8 @@ CODE_SAMPLE
return null;
}
$upperCaseName = \strtoupper($enumCaseName);
$enumConstFetch = $this->nodeFactory->createClassConstFetch($className, $upperCaseName);
return new PropertyFetch($enumConstFetch, $property);
$classConstFetch = $this->nodeFactory->createClassConstFetch($className, $upperCaseName);
return new PropertyFetch($classConstFetch, $property);
}
private function refactorMethodCall(MethodCall $methodCall, string $methodName) : ?\PhpParser\Node\Expr\PropertyFetch
{

View File

@ -132,11 +132,11 @@ CODE_SAMPLE
if ($constName === null) {
return \false;
}
$newValue = $this->nodeFactory->createClassConstFetch($attributeKeyToClassConstFetch->getConstantClass(), $constName);
if ($arg->value instanceof ClassConstFetch && $this->getName($arg->value) === $this->getName($newValue)) {
$classConstFetch = $this->nodeFactory->createClassConstFetch($attributeKeyToClassConstFetch->getConstantClass(), $constName);
if ($arg->value instanceof ClassConstFetch && $this->getName($arg->value) === $this->getName($classConstFetch)) {
return \false;
}
$arg->value = $newValue;
$arg->value = $classConstFetch;
return \true;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '459843b1617a401d02e8cf5e6a1054f43f069f0d';
public const PACKAGE_VERSION = 'de31e6f73765bef8a7285a00114037c07712add7';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-06-12 05:07:48';
public const RELEASE_DATE = '2024-06-12 06:08:06';
/**
* @var int
*/

View File

@ -29,11 +29,11 @@ final class RectorContainerFactory
private function createFromConfigs(array $configFiles) : Container
{
$lazyContainerFactory = new \Rector\DependencyInjection\LazyContainerFactory();
$container = $lazyContainerFactory->create();
$rectorConfig = $lazyContainerFactory->create();
foreach ($configFiles as $configFile) {
$container->import($configFile);
$rectorConfig->import($configFile);
}
$container->boot();
return $container;
$rectorConfig->boot();
return $rectorConfig;
}
}

View File

@ -289,8 +289,8 @@ final class ValueResolver
// fallback to constant reference itself, to avoid fatal error
return $classConstantReference;
}
$constantReflection = $classReflection->getConstant($constant);
$valueExpr = $constantReflection->getValueExpr();
$classConstantReflection = $classReflection->getConstant($constant);
$valueExpr = $classConstantReflection->getValueExpr();
if ($valueExpr instanceof ConstFetch) {
return $this->resolveExprValueForConst($valueExpr);
}