Skip to content
Merged
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 @@ -9,8 +9,8 @@
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -42,6 +42,7 @@ final class AddReturnTypeWillChangeAttributeRector extends AbstractRector

public function __construct(
private readonly ReflectionProvider $reflectionProvider,
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer
) {
}

Expand Down Expand Up @@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node
$hasChanged = false;

foreach ($node->getMethods() as $classMethod) {
if ($this->hasReturnTypeWillChangeAttribute($classMethod)) {
if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, self::RETURN_TYPE_WILL_CHANGE)) {
continue;
}

Expand All @@ -124,7 +125,7 @@ public function refactor(Node $node): ?Node
]);

$hasChanged = true;
break;
continue 2;
}
}

Expand All @@ -134,17 +135,4 @@ public function refactor(Node $node): ?Node

return null;
}

private function hasReturnTypeWillChangeAttribute(ClassMethod $classMethod): bool
{
foreach ($classMethod->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
if ($attr->name->getLast() === self::RETURN_TYPE_WILL_CHANGE) {
return true;
}
}
}

return false;
}
}
Loading