Skip to content

Commit

Permalink
[Renaming] Improve performance of RenamePropertyRector (#3698)
Browse files Browse the repository at this point in the history
* [Renaming] Improve performance of RenamePropertyRector

* early null assign

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Apr 28, 2023
1 parent 92a992e commit 7d16e3d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Renaming\Rector\PropertyFetch;

use PHPStan\Type\Type;
use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Identifier;
Expand Down Expand Up @@ -113,6 +114,7 @@ private function renameProperty(ClassLike $classLike, RenameProperty $renameProp
private function processFromPropertyFetch(PropertyFetch $propertyFetch): ?PropertyFetch
{
$class = $this->betterNodeFinder->findParentType($propertyFetch, Class_::class);
$nodeVarType = null;

foreach ($this->renamedProperties as $renamedProperty) {
$oldProperty = $renamedProperty->getOldProperty();
Expand All @@ -123,8 +125,11 @@ private function processFromPropertyFetch(PropertyFetch $propertyFetch): ?Proper
if (! $this->isObjectType($propertyFetch->var, $renamedProperty->getObjectType())) {
continue;
}

if (! $nodeVarType instanceof Type) {
$nodeVarType = $this->nodeTypeResolver->getType($propertyFetch->var);
}

$nodeVarType = $this->nodeTypeResolver->getType($propertyFetch->var);
if ($nodeVarType instanceof ThisType && $class instanceof ClassLike) {
$this->renameProperty($class, $renamedProperty);
}
Expand Down

0 comments on commit 7d16e3d

Please sign in to comment.