Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace Rector\Tests\Unambiguous\Rector\Class_\RemoveReturnThisFromSetterClass

final class SomeClass
{
private string $name;
private string $nameValue;

public function setName(string $name): self
{
$this->name = $name;
$this->nameValue = $name;

return $this;
}
Expand All @@ -22,11 +22,11 @@ namespace Rector\Tests\Unambiguous\Rector\Class_\RemoveReturnThisFromSetterClass

final class SomeClass
{
private string $name;
private string $nameValue;

public function setName(string $name): void
{
$this->name = $name;
$this->nameValue = $name;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function hasOnlyPropertyAssign(ClassMethod $classMethod, string $property
return $this->isLocalPropertyVariableAssign($onlyClassMethodStmt, $propertyName);
}

public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod, string $propertyName): bool
public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod): bool
{
$stmts = (array) $classMethod->stmts;
if (count($stmts) !== 2) {
Expand All @@ -63,7 +63,7 @@ public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod, string
$possibleAssignStmt = $stmts[0];
$possibleReturnThis = $stmts[1];

if (! $this->isLocalPropertyVariableAssign($possibleAssignStmt, $propertyName)) {
if (! $this->isLocalPropertyVariableAssign($possibleAssignStmt, null)) {
return false;
}

Expand All @@ -80,7 +80,7 @@ public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod, string
return $this->nodeNameResolver->isName($returnExpr, 'this');
}

private function isLocalPropertyVariableAssign(Stmt $onlyClassMethodStmt, string $propertyName): bool
private function isLocalPropertyVariableAssign(Stmt $onlyClassMethodStmt, ?string $propertyName): bool
{
if (! $onlyClassMethodStmt instanceof Expression) {
return false;
Expand All @@ -102,6 +102,10 @@ private function isLocalPropertyVariableAssign(Stmt $onlyClassMethodStmt, string
return false;
}

return $this->nodeNameResolver->isName($propertyFetch->name, $propertyName);
if ($propertyName) {
return $this->nodeNameResolver->isName($propertyFetch->name, $propertyName);
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function __construct(

public function inferProperty(Property $property, Class_ $class): ?Type
{
/** @var string $propertyName */
$propertyName = $this->nodeNameResolver->getName($property);

foreach ($class->getMethods() as $classMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function refactor(Node $node): ?Class_
continue;
}

if (! $this->classMethodAndPropertyAnalyzer->hasPropertyAssignWithReturnThis($classMethod, $paramName)) {
if (! $this->classMethodAndPropertyAnalyzer->hasPropertyAssignWithReturnThis($classMethod)) {
continue;
}

Expand Down