Skip to content

Commit

Permalink
[Naming] Remove parent attribute usage on ExpectedNameResolver (#4180)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jun 11, 2023
1 parent f7b43d4 commit 405d9f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions rules/Naming/Naming/ExpectedNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use PHPStan\Type\Type;
use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver;
use Rector\Naming\ValueObject\ExpectedName;
use Rector\Naming\ValueObject\VariableAndCallForeach;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;

Expand Down Expand Up @@ -146,8 +146,9 @@ public function resolveForCall(MethodCall | StaticCall | FuncCall $expr): ?strin
return null;
}

public function resolveForForeach(MethodCall | StaticCall | FuncCall $expr): ?string
public function resolveForForeach(VariableAndCallForeach $variableAndCallForeach): ?string
{
$expr = $variableAndCallForeach->getCall();
if ($this->isDynamicNameCall($expr)) {
return null;
}
Expand All @@ -164,7 +165,7 @@ public function resolveForForeach(MethodCall | StaticCall | FuncCall $expr): ?st

$innerReturnedType = null;
if ($returnedType instanceof ArrayType) {
$innerReturnedType = $this->resolveReturnTypeFromArrayType($expr, $returnedType);
$innerReturnedType = $this->resolveReturnTypeFromArrayType($returnedType);
if (! $innerReturnedType instanceof Type) {
return null;
}
Expand Down Expand Up @@ -208,13 +209,8 @@ private function isDynamicNameCall(MethodCall | StaticCall | FuncCall $expr): bo
return $expr->name instanceof FuncCall;
}

private function resolveReturnTypeFromArrayType(FuncCall|MethodCall|StaticCall $expr, ArrayType $arrayType): ?Type
private function resolveReturnTypeFromArrayType(ArrayType $arrayType): ?Type
{
$parentNode = $expr->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Foreach_) {
return null;
}

if (! $arrayType->getItemType() instanceof ObjectType) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function refactor(Node $node): ?Node
return null;
}

$expectedName = $this->expectedNameResolver->resolveForForeach($variableAndCallForeach->getCall());
$expectedName = $this->expectedNameResolver->resolveForForeach($variableAndCallForeach);
if ($expectedName === null) {
return null;
}
Expand Down

0 comments on commit 405d9f8

Please sign in to comment.