Skip to content

Commit

Permalink
[NodeManipulator] Remove parent lookup on PropertyFetchAssignManipula…
Browse files Browse the repository at this point in the history
…tor (#4037)
  • Loading branch information
samsonasik committed May 31, 2023
1 parent 81e8c74 commit bdc2fc9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion rules/Php81/Rector/Property/ReadOnlyPropertyRector.php
Expand Up @@ -163,7 +163,7 @@ private function refactorProperty(Class_ $class, Property $property, Scope $scop
return null;
}

if ($this->propertyFetchAssignManipulator->isAssignedMultipleTimesInConstructor($property)) {
if ($this->propertyFetchAssignManipulator->isAssignedMultipleTimesInConstructor($class, $property)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/RectorKernel.php
Expand Up @@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v43';
private const CACHE_KEY = 'v44';

private ContainerInterface|null $container = null;

Expand Down
12 changes: 2 additions & 10 deletions src/NodeManipulator/PropertyFetchAssignManipulator.php
Expand Up @@ -7,13 +7,11 @@
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Property;
use PhpParser\NodeTraverser;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\ValueObject\MethodName;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
Expand All @@ -23,19 +21,13 @@ final class PropertyFetchAssignManipulator
public function __construct(
private readonly SimpleCallableNodeTraverser $simpleCallableNodeTraverser,
private readonly NodeNameResolver $nodeNameResolver,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly PropertyFetchAnalyzer $propertyFetchAnalyzer
) {
}

public function isAssignedMultipleTimesInConstructor(Property $property): bool
public function isAssignedMultipleTimesInConstructor(Class_ $class, Property $property): bool
{
$classLike = $this->betterNodeFinder->findParentType($property, ClassLike::class);
if (! $classLike instanceof ClassLike) {
return false;
}

$classMethod = $classLike->getMethod(MethodName::CONSTRUCT);
$classMethod = $class->getMethod(MethodName::CONSTRUCT);
if (! $classMethod instanceof ClassMethod) {
return false;
}
Expand Down

0 comments on commit bdc2fc9

Please sign in to comment.