Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PostRector] Move instanceof check early to avoid unnecessary SimpleParameterProvider static call check when possible #5907

Merged
merged 1 commit into from
May 22, 2024
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
8 changes: 4 additions & 4 deletions src/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function __construct(

public function enterNode(Node $node): ?Node
{
if (! $node instanceof Stmt && ! $node instanceof Param && ! $node instanceof FullyQualified) {
return null;
}

if (! SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_NAMES)) {
return null;
}
Expand All @@ -61,10 +65,6 @@ public function enterNode(Node $node): ?Node
return $this->processNodeName($node, $file);
}

if (! $node instanceof Stmt && ! $node instanceof Param) {
return null;
}

$shouldImportDocBlocks = SimpleParameterProvider::provideBoolParameter(Option::AUTO_IMPORT_DOC_BLOCK_NAMES);
if (! $shouldImportDocBlocks) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/PostRector/Rector/UnusedImportRemovingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function __construct(

public function enterNode(Node $node): ?Node
{
if (! SimpleParameterProvider::provideBoolParameter(Option::REMOVE_UNUSED_IMPORTS)) {
if (! $node instanceof Namespace_ && ! $node instanceof FileWithoutNamespace) {
return null;
}

if (! $node instanceof Namespace_ && ! $node instanceof FileWithoutNamespace) {
if (! SimpleParameterProvider::provideBoolParameter(Option::REMOVE_UNUSED_IMPORTS)) {
return null;
}

Expand Down