From b2c9e52bf0776d2475e4d0533267cd11299826f6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 22 May 2024 09:12:25 +0700 Subject: [PATCH] [PostRector] Move instanceof check early before SimpleParameterProvider static call check (#5907) --- src/PostRector/Rector/NameImportingPostRector.php | 8 ++++---- src/PostRector/Rector/UnusedImportRemovingPostRector.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PostRector/Rector/NameImportingPostRector.php b/src/PostRector/Rector/NameImportingPostRector.php index 26c9b71afba..7a0e86575e0 100644 --- a/src/PostRector/Rector/NameImportingPostRector.php +++ b/src/PostRector/Rector/NameImportingPostRector.php @@ -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; } @@ -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; diff --git a/src/PostRector/Rector/UnusedImportRemovingPostRector.php b/src/PostRector/Rector/UnusedImportRemovingPostRector.php index fab2b761bdf..5f76bc8713f 100644 --- a/src/PostRector/Rector/UnusedImportRemovingPostRector.php +++ b/src/PostRector/Rector/UnusedImportRemovingPostRector.php @@ -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; }