diff --git a/config/set/order.php b/config/set/order.php index 819be93c6e1..7a0800c7ed0 100644 --- a/config/set/order.php +++ b/config/set/order.php @@ -2,18 +2,10 @@ declare(strict_types=1); -use Rector\Order\Rector\Class_\OrderClassConstantsByIntegerValueRector; -use Rector\Order\Rector\Class_\OrderConstantsByVisibilityRector; -use Rector\Order\Rector\Class_\OrderMethodsByVisibilityRector; use Rector\Order\Rector\Class_\OrderPrivateMethodsByUseRector; -use Rector\Order\Rector\Class_\OrderPropertiesByVisibilityRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); $services->set(OrderPrivateMethodsByUseRector::class); - $services->set(OrderClassConstantsByIntegerValueRector::class); - $services->set(OrderMethodsByVisibilityRector::class); - $services->set(OrderPropertiesByVisibilityRector::class); - $services->set(OrderConstantsByVisibilityRector::class); }; diff --git a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/Fixture/fixture.php.inc b/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/Fixture/fixture.php.inc deleted file mode 100644 index edf1594744c..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/Fixture/from_zero.php.inc b/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/Fixture/from_zero.php.inc deleted file mode 100644 index b5fef8932ba..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/Fixture/from_zero.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/OrderClassConstantsByIntegerValueRectorTest.php b/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/OrderClassConstantsByIntegerValueRectorTest.php deleted file mode 100644 index 2f317d9c4a1..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/OrderClassConstantsByIntegerValueRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/config/configured_rule.php b/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/config/configured_rule.php deleted file mode 100644 index a5ecb3ec6bf..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -services(); - $services->set(OrderClassConstantsByIntegerValueRector::class); -}; diff --git a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/Fixture/abstract.php.inc b/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/Fixture/abstract.php.inc deleted file mode 100644 index 95ca63d91e1..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/Fixture/abstract.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/Fixture/fixture.php.inc b/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/Fixture/fixture.php.inc deleted file mode 100644 index 73d81c8dbc6..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/OrderConstantsByVisibilityRectorTest.php b/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/OrderConstantsByVisibilityRectorTest.php deleted file mode 100644 index 42f4d9c530f..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/OrderConstantsByVisibilityRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/config/configured_rule.php b/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/config/configured_rule.php deleted file mode 100644 index 57a3a8df398..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderConstantsByVisibilityRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -services(); - $services->set(OrderConstantsByVisibilityRector::class); -}; diff --git a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Fixture/fixture.php.inc b/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Fixture/fixture.php.inc deleted file mode 100644 index f22d126c9ee..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Fixture/same_names.php.inc b/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Fixture/same_names.php.inc deleted file mode 100644 index 13a37db15de..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Fixture/same_names.php.inc +++ /dev/null @@ -1,29 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/OrderFirstLevelClassStatementsRectorTest.php b/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/OrderFirstLevelClassStatementsRectorTest.php deleted file mode 100644 index c52d097ce64..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/OrderFirstLevelClassStatementsRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Source/TraitName.php b/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Source/TraitName.php deleted file mode 100644 index 8e3510b2940..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderFirstLevelClassStatementsRector/Source/TraitName.php +++ /dev/null @@ -1,10 +0,0 @@ -services(); - $services->set(OrderFirstLevelClassStatementsRector::class); -}; diff --git a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/abstract.php.inc b/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/abstract.php.inc deleted file mode 100644 index 2ccdef304b5..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/abstract.php.inc +++ /dev/null @@ -1,58 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/fixture.php.inc b/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/fixture.php.inc deleted file mode 100644 index 7330790fae2..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,91 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/magic_phpunit_preferred_order.php.inc b/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/magic_phpunit_preferred_order.php.inc deleted file mode 100644 index 531d36f22b0..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/Fixture/magic_phpunit_preferred_order.php.inc +++ /dev/null @@ -1,58 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/OrderMethodsByVisibilityRectorTest.php b/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/OrderMethodsByVisibilityRectorTest.php deleted file mode 100644 index e9953724c27..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/OrderMethodsByVisibilityRectorTest.php +++ /dev/null @@ -1,35 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/config/configured_rule.php b/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/config/configured_rule.php deleted file mode 100644 index 808181d10e0..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderMethodsByVisibilityRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -services(); - $services->set(OrderMethodsByVisibilityRector::class); -}; diff --git a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/abstract.php.inc b/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/abstract.php.inc deleted file mode 100644 index ef211a2779b..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/abstract.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/fixture.php.inc b/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/fixture.php.inc deleted file mode 100644 index 3d965f54bcb..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/trait.php.inc b/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/trait.php.inc deleted file mode 100644 index 4f4b08b3c64..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/Fixture/trait.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/OrderPropertiesByVisibilityRectorTest.php b/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/OrderPropertiesByVisibilityRectorTest.php deleted file mode 100644 index 17054052edf..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/OrderPropertiesByVisibilityRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/config/configured_rule.php b/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/config/configured_rule.php deleted file mode 100644 index 91823963b72..00000000000 --- a/rules-tests/Order/Rector/Class_/OrderPropertiesByVisibilityRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -services(); - $services->set(OrderPropertiesByVisibilityRector::class); -}; diff --git a/rules/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector.php b/rules/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector.php deleted file mode 100644 index c7a2ac932e7..00000000000 --- a/rules/Order/Rector/Class_/OrderClassConstantsByIntegerValueRector.php +++ /dev/null @@ -1,141 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - $numericClassConstsByKey = $this->resolveClassConstByPosition($node); - if ($numericClassConstsByKey === []) { - return null; - } - - $classConstConstsByValue = $this->resolveClassConstConstByUniqueValue($numericClassConstsByKey); - - $sortedClassConstConstsByValue = $classConstConstsByValue; - asort($sortedClassConstConstsByValue); - - $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($sortedClassConstConstsByValue, $classConstConstsByValue); - if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { - return null; - } - - $this->stmtOrder->reorderClassStmtsByOldToNewKeys($node, $oldToNewKeys); - - return $node; - } - - /** - * @return ClassConst[] - */ - private function resolveClassConstByPosition(Class_ $class): array - { - $classConstConstsByValue = []; - foreach ($class->stmts as $key => $classStmt) { - if (! $classStmt instanceof ClassConst) { - continue; - } - - if (count($classStmt->consts) !== 1) { - continue; - } - - $classConstConst = $classStmt->consts[0]; - if (! $classConstConst->value instanceof LNumber) { - continue; - } - - $classConstConstsByValue[$key] = $classStmt; - } - - return $classConstConstsByValue; - } - - /** - * @param array $numericClassConstsByKey - * @return array - */ - private function resolveClassConstConstByUniqueValue(array $numericClassConstsByKey): array - { - $classConstConstsByValue = []; - foreach ($numericClassConstsByKey as $position => $numericClassConst) { - $constantValue = $this->valueResolver->getValue($numericClassConst->consts[0]->value); - $classConstConstsByValue[$position] = $constantValue; - } - - $arrayCountValue = array_count_values($classConstConstsByValue); - - // work only with unique constants - foreach ($classConstConstsByValue as $position => $constantValue) { - if ($arrayCountValue[$constantValue] > 1) { - unset($classConstConstsByValue[$position]); - } - } - return $classConstConstsByValue; - } -} diff --git a/rules/Order/Rector/Class_/OrderConstantsByVisibilityRector.php b/rules/Order/Rector/Class_/OrderConstantsByVisibilityRector.php deleted file mode 100644 index 6e7c7d83bef..00000000000 --- a/rules/Order/Rector/Class_/OrderConstantsByVisibilityRector.php +++ /dev/null @@ -1,80 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - $currentClassConstsOrder = $this->stmtOrder->getStmtsOfTypeOrder($node, ClassConst::class); - $classConstsInDesiredOrder = $this->stmtVisibilitySorter->sortConstants($node); - - $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($classConstsInDesiredOrder, $currentClassConstsOrder); - - if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { - return null; - } - - $this->stmtOrder->reorderClassStmtsByOldToNewKeys($node, $oldToNewKeys); - return $node; - } -} diff --git a/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php b/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php deleted file mode 100644 index 2cc4470a3f9..00000000000 --- a/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php +++ /dev/null @@ -1,107 +0,0 @@ - - */ - private const TYPE_TO_RANK = [ - ClassMethod::class => 3, - Property::class => 2, - ClassConst::class => 1, - ]; - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition('Orders first level Class statements', [ - new CodeSample( - <<<'CODE_SAMPLE' -final class SomeClass -{ - public function functionName(); - protected $propertyName; - private const CONST_NAME = 'constant_value'; - use TraitName; -} -CODE_SAMPLE - - , - <<<'CODE_SAMPLE' -final class SomeClass -{ - use TraitName; - private const CONST_NAME = 'constant_value'; - protected $propertyName; - public function functionName(); -} -CODE_SAMPLE - ), - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [Class_::class, Trait_::class]; - } - - /** - * @param Class_|Trait_ $node - */ - public function refactor(Node $node): ?Node - { - $node->stmts = $this->getStmtsInDesiredPosition($node->stmts); - - return $node; - } - - /** - * @param Stmt[] $stmts - * @return Stmt[] - */ - private function getStmtsInDesiredPosition(array $stmts): array - { - uasort( - $stmts, - fn (Stmt $firstStmt, Stmt $secondStmt): int => [ - $this->resolveClassElementRank($firstStmt), - $firstStmt->getLine(), - ] - <=> [$this->resolveClassElementRank($secondStmt), $secondStmt->getLine()] - ); - - return $stmts; - } - - private function resolveClassElementRank(Stmt $stmt): int - { - foreach (self::TYPE_TO_RANK as $type => $rank) { - if (is_a($stmt, $type, true)) { - return $rank; - } - } - - // TraitUse - return 0; - } -} diff --git a/rules/Order/Rector/Class_/OrderMethodsByVisibilityRector.php b/rules/Order/Rector/Class_/OrderMethodsByVisibilityRector.php deleted file mode 100644 index 587263e42da..00000000000 --- a/rules/Order/Rector/Class_/OrderMethodsByVisibilityRector.php +++ /dev/null @@ -1,129 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class, Trait_::class]; - } - - /** - * @param Class_|Trait_ $node - */ - public function refactor(Node $node): ?Node - { - $currentMethodsOrder = $this->stmtOrder->getStmtsOfTypeOrder($node, ClassMethod::class); - $methodsInDesiredOrder = $this->getMethodsInDesiredOrder($node); - - $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($methodsInDesiredOrder, $currentMethodsOrder); - - // nothing to re-order - if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { - return null; - } - - $this->stmtOrder->reorderClassStmtsByOldToNewKeys($node, $oldToNewKeys); - return $node; - } - - /** - * @return string[] - */ - private function getMethodsInDesiredOrder(ClassLike $classLike): array - { - $classMethodNames = $this->stmtVisibilitySorter->sortMethods($classLike); - return $this->applyPreferredPosition($classMethodNames); - } - - /** - * @param string[] $classMethods - * @return string[] - */ - private function applyPreferredPosition(array $classMethods): array - { - $mergedMethods = array_merge(self::PREFERRED_ORDER, $classMethods); - return array_unique($mergedMethods); - } -} diff --git a/rules/Order/Rector/Class_/OrderPropertiesByVisibilityRector.php b/rules/Order/Rector/Class_/OrderPropertiesByVisibilityRector.php deleted file mode 100644 index 10ce9873966..00000000000 --- a/rules/Order/Rector/Class_/OrderPropertiesByVisibilityRector.php +++ /dev/null @@ -1,82 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class, Trait_::class]; - } - - /** - * @param Class_|Trait_ $node - */ - public function refactor(Node $node): ?Node - { - $currentPropertiesOrder = $this->stmtOrder->getStmtsOfTypeOrder($node, Property::class); - $propertiesInDesiredOrder = $this->stmtVisibilitySorter->sortProperties($node); - - $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($propertiesInDesiredOrder, $currentPropertiesOrder); - - // nothing to re-order - if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { - return null; - } - - $this->stmtOrder->reorderClassStmtsByOldToNewKeys($node, $oldToNewKeys); - return $node; - } -}