Skip to content
Open
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 @@ -27,6 +27,11 @@ final class ChangeMethodVisibilityRector extends AbstractRector implements Confi
*/
private array $methodVisibilities = [];

/**
* @var string[]
*/
private array $methodNames = [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel comfortable adding a non-readonly property with a state.
Can you handle similar check with any other way of cache?


public function __construct(
private readonly ParentClassScopeResolver $parentClassScopeResolver,
private readonly VisibilityManipulator $visibilityManipulator,
Expand Down Expand Up @@ -94,6 +99,10 @@ public function refactor(Node $node): ?Node
return null;
}

if (! $this->isNames($node, $this->methodNames)) {
return null;
}

$scope = ScopeFetcher::fetch($node);
$parentClassName = $this->parentClassScopeResolver->resolveParentClassName($scope);
if ($parentClassName === null) {
Expand Down Expand Up @@ -125,5 +134,9 @@ public function configure(array $configuration): void
Assert::allIsAOf($configuration, ChangeMethodVisibility::class);

$this->methodVisibilities = $configuration;
$this->methodNames = array_map(
static fn (ChangeMethodVisibility $changeMethodVisibility): string => $changeMethodVisibility->getMethod(),
$configuration
);
}
}
Loading