Skip to content

Commit 7c51a40

Browse files
committed
allow different property name
1 parent 755d81c commit 7c51a40

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function hasOnlyPropertyAssign(ClassMethod $classMethod, string $property
5353
return $this->isLocalPropertyVariableAssign($onlyClassMethodStmt, $propertyName);
5454
}
5555

56-
public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod, string $propertyName): bool
56+
public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod): bool
5757
{
5858
$stmts = (array) $classMethod->stmts;
5959
if (count($stmts) !== 2) {
@@ -63,7 +63,7 @@ public function hasPropertyAssignWithReturnThis(ClassMethod $classMethod, string
6363
$possibleAssignStmt = $stmts[0];
6464
$possibleReturnThis = $stmts[1];
6565

66-
if (! $this->isLocalPropertyVariableAssign($possibleAssignStmt, $propertyName)) {
66+
if (! $this->isLocalPropertyVariableAssign($possibleAssignStmt, null)) {
6767
return false;
6868
}
6969

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

83-
private function isLocalPropertyVariableAssign(Stmt $onlyClassMethodStmt, string $propertyName): bool
83+
private function isLocalPropertyVariableAssign(Stmt $onlyClassMethodStmt, ?string $propertyName): bool
8484
{
8585
if (! $onlyClassMethodStmt instanceof Expression) {
8686
return false;
@@ -102,6 +102,10 @@ private function isLocalPropertyVariableAssign(Stmt $onlyClassMethodStmt, string
102102
return false;
103103
}
104104

105-
return $this->nodeNameResolver->isName($propertyFetch->name, $propertyName);
105+
if ($propertyName) {
106+
return $this->nodeNameResolver->isName($propertyFetch->name, $propertyName);
107+
}
108+
109+
return true;
106110
}
107111
}

rules/TypeDeclaration/TypeInferer/PropertyTypeInferer/SetterTypeDeclarationPropertyTypeInferer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function __construct(
2424

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

3029
foreach ($class->getMethods() as $classMethod) {

rules/Unambiguous/Rector/Class_/RemoveReturnThisFromSetterClassMethodRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function refactor(Node $node): ?Class_
101101
continue;
102102
}
103103

104-
if (! $this->classMethodAndPropertyAnalyzer->hasPropertyAssignWithReturnThis($classMethod, $paramName)) {
104+
if (! $this->classMethodAndPropertyAnalyzer->hasPropertyAssignWithReturnThis($classMethod)) {
105105
continue;
106106
}
107107

0 commit comments

Comments
 (0)