From d0ae8d2c7b49d74f3ad887c236385f8cfa510ff5 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Fri, 22 Jan 2021 18:46:27 +0100 Subject: [PATCH] [Order] Drop OrderPublicInterfaceMethodRector as not practical for use and too much opinionated scope --- rector.php | 6 - rules/coding-style/src/Node/NameImporter.php | 4 +- .../OrderPublicInterfaceMethodRector.php | 153 ------------------ .../Fixture/fixture.php.inc | 36 ----- .../OrderPublicInterfaceMethodRectorTest.php | 41 ----- .../Source/FoodRecipeInterface.php | 12 -- 6 files changed, 1 insertion(+), 251 deletions(-) delete mode 100644 rules/order/src/Rector/Class_/OrderPublicInterfaceMethodRector.php delete mode 100644 rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Fixture/fixture.php.inc delete mode 100644 rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/OrderPublicInterfaceMethodRectorTest.php delete mode 100644 rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Source/FoodRecipeInterface.php diff --git a/rector.php b/rector.php index 3da449ed23e8..7a60b2edac93 100644 --- a/rector.php +++ b/rector.php @@ -38,12 +38,6 @@ ]]); $services->set(AutoInPhpSymfonyConfigRector::class); - $services->set(OrderPublicInterfaceMethodRector::class) - ->call('configure', [[ - OrderPublicInterfaceMethodRector::METHOD_ORDER_BY_INTERFACES => [ - PhpRectorInterface::class => ['getNodeTypes', 'getRuleDefinition', 'refactor'], - ], - ]]); $parameters = $containerConfigurator->parameters(); diff --git a/rules/coding-style/src/Node/NameImporter.php b/rules/coding-style/src/Node/NameImporter.php index 12b954e3862c..f5332c15db4b 100644 --- a/rules/coding-style/src/Node/NameImporter.php +++ b/rules/coding-style/src/Node/NameImporter.php @@ -198,9 +198,7 @@ private function isFunctionOrConstantImportWithSingleName(Name $name): bool if ($autoImportNames && ! $parentNode instanceof Node && ! Strings::contains( $fullName, '\\' - ) && function_exists( - $fullName - )) { + ) && function_exists($fullName)) { return true; } diff --git a/rules/order/src/Rector/Class_/OrderPublicInterfaceMethodRector.php b/rules/order/src/Rector/Class_/OrderPublicInterfaceMethodRector.php deleted file mode 100644 index a344054ad5b0..000000000000 --- a/rules/order/src/Rector/Class_/OrderPublicInterfaceMethodRector.php +++ /dev/null @@ -1,153 +0,0 @@ -classManipulator = $classManipulator; - $this->stmtOrder = $stmtOrder; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition('Order public methods required by interface in custom orderer', [ - new ConfiguredCodeSample( - <<<'CODE_SAMPLE' -class SomeClass implements FoodRecipeInterface -{ - public function process() - { - } - - public function getDescription() - { - } -} -CODE_SAMPLE -, - <<<'CODE_SAMPLE' -class SomeClass implements FoodRecipeInterface -{ - public function getDescription() - { - } - public function process() - { - } -} -CODE_SAMPLE - , [ - self::METHOD_ORDER_BY_INTERFACES => [ - 'FoodRecipeInterface' => ['getDescription', 'process'], - ], - ]), - ]); - } - - /** - * @return string[] - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - $implementedInterfaces = $this->classManipulator->getImplementedInterfaceNames($node); - if ($implementedInterfaces === []) { - return null; - } - - $publicMethodOrderByKey = $this->collectPublicMethods($node); - - foreach ($implementedInterfaces as $implementedInterface) { - $methodOrder = $this->methodOrderByInterfaces[$implementedInterface] ?? null; - if ($methodOrder === null) { - continue; - } - - $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($publicMethodOrderByKey, $methodOrder); - - // nothing to re-order - if (array_keys($oldToNewKeys) === array_values($oldToNewKeys)) { - return null; - } - - $this->stmtOrder->reorderClassStmtsByOldToNewKeys($node, $oldToNewKeys); - - break; - } - - return $node; - } - - public function configure(array $configuration): void - { - $this->methodOrderByInterfaces = $configuration[self::METHOD_ORDER_BY_INTERFACES] ?? []; - } - - /** - * @return string[] - */ - private function collectPublicMethods(Class_ $class): array - { - $publicClassMethods = []; - - foreach ($class->stmts as $key => $classStmt) { - if (! $classStmt instanceof ClassMethod) { - continue; - } - - if (! $classStmt->isPublic()) { - continue; - } - - /** @var string $classMethodName */ - $classMethodName = $this->getName($classStmt); - $publicClassMethods[$key] = $classMethodName; - } - - return $publicClassMethods; - } -} diff --git a/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Fixture/fixture.php.inc b/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Fixture/fixture.php.inc deleted file mode 100644 index 15e4581f96d6..000000000000 --- a/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,36 +0,0 @@ - ------ - diff --git a/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/OrderPublicInterfaceMethodRectorTest.php b/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/OrderPublicInterfaceMethodRectorTest.php deleted file mode 100644 index 9f9d129d24ea..000000000000 --- a/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/OrderPublicInterfaceMethodRectorTest.php +++ /dev/null @@ -1,41 +0,0 @@ -doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - /** - * @return array - */ - protected function getRectorsWithConfiguration(): array - { - return [ - OrderPublicInterfaceMethodRector::class => [ - OrderPublicInterfaceMethodRector::METHOD_ORDER_BY_INTERFACES => [ - FoodRecipeInterface::class => ['getDescription', 'process'], - ], - ], - ]; - } -} diff --git a/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Source/FoodRecipeInterface.php b/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Source/FoodRecipeInterface.php deleted file mode 100644 index 2711dfe0403f..000000000000 --- a/rules/order/tests/Rector/Class_/OrderPublicInterfaceMethodRector/Source/FoodRecipeInterface.php +++ /dev/null @@ -1,12 +0,0 @@ -