From 23dde903b7638f45e0f1ec95176919e9d69c8439 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Mon, 7 Aug 2017 17:41:58 +0200 Subject: [PATCH] refactor NodeVisitor to Rectors --- ...ceReplaceDeprecatedConstantNodeVisitor.php | 49 ------------------- .../Nette/NetteObjectToSmartTraitRector.php | 2 +- .../RemoveConfiguratorConstantsRector.php | 49 +++++++++++++++++++ .../PHPUnit/AbstractReconstructorTestCase.php | 2 +- .../ReplaceOldConstantNodeVisitor.php | 23 --------- .../Test.php | 2 +- .../correct/correct.php.inc | 0 .../wrong/wrong.php.inc | 0 tests/config/services.yml | 6 --- 9 files changed, 52 insertions(+), 81 deletions(-) delete mode 100644 src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php create mode 100644 src/Rector/Contrib/Nette/RemoveConfiguratorConstantsRector.php delete mode 100644 tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php rename tests/{NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor => Rector/Contrib/Nette/RemoveConfiguratorConstantsRector}/Test.php (79%) rename tests/{NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor => Rector/Contrib/Nette/RemoveConfiguratorConstantsRector}/correct/correct.php.inc (100%) rename tests/{NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor => Rector/Contrib/Nette/RemoveConfiguratorConstantsRector}/wrong/wrong.php.inc (100%) delete mode 100644 tests/config/services.yml diff --git a/src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php b/src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php deleted file mode 100644 index e2182e9b7d3..00000000000 --- a/src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php +++ /dev/null @@ -1,49 +0,0 @@ -isCandidate($node)) { - $this->refactor($node); - return NodeTraverser::DONT_TRAVERSE_CHILDREN; - } - - return null; - } - - private function isCandidate(Node $node): bool - { - if ($node instanceof ClassConstFetch) { - if ((string) $node->class !== $this->getClassName()) { - return false; - } - - if ((string) $node->name !== $this->getOldConstantName()) { - return false; - } - - return true; - } - - return false; - } - - private function refactor(ClassConstFetch $classConstFetchNode): void - { - $classConstFetchNode->name->name = $this->getNewConstantName(); - } -} diff --git a/src/Rector/Contrib/Nette/NetteObjectToSmartTraitRector.php b/src/Rector/Contrib/Nette/NetteObjectToSmartTraitRector.php index 01eb3bedc49..82c99655ce0 100644 --- a/src/Rector/Contrib/Nette/NetteObjectToSmartTraitRector.php +++ b/src/Rector/Contrib/Nette/NetteObjectToSmartTraitRector.php @@ -11,7 +11,7 @@ use Rector\Deprecation\SetNames; use Rector\Rector\AbstractRector; /** - * Reflects @link https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject + * Covers https://doc.nette.org/en/2.4/migration-2-4#toc-nette-smartobject */ final class NetteObjectToSmartTraitRector extends AbstractRector { diff --git a/src/Rector/Contrib/Nette/RemoveConfiguratorConstantsRector.php b/src/Rector/Contrib/Nette/RemoveConfiguratorConstantsRector.php new file mode 100644 index 00000000000..55614ea0739 --- /dev/null +++ b/src/Rector/Contrib/Nette/RemoveConfiguratorConstantsRector.php @@ -0,0 +1,49 @@ +class !== 'Nette\Configurator') { + return false; + } + + if (! in_array((string) $node->name, ['DEVELOPMENT', 'PRODUCTION'], true)) { + return false; + } + + return true; + } + + return false; + } + + /** + * @param ClassConstFetch $classConstFetchNode + */ + public function refactor($classConstFetchNode): void + { + dump($classConstFetchNode->name->name); + die; + + $classConstFetchNode->name->name = $this->getNewConstantName(); + } + + public function getSetName(): string + { + return SetNames::NETTE; + } + + public function sinceVersion(): float + { + return 2.3; + } +} diff --git a/src/Testing/PHPUnit/AbstractReconstructorTestCase.php b/src/Testing/PHPUnit/AbstractReconstructorTestCase.php index f3dcce41136..730ad2629e3 100644 --- a/src/Testing/PHPUnit/AbstractReconstructorTestCase.php +++ b/src/Testing/PHPUnit/AbstractReconstructorTestCase.php @@ -22,7 +22,7 @@ abstract class AbstractReconstructorTestCase extends TestCase protected function setUp(): void { - $this->container = (new ContainerFactory)->createWithConfig(__DIR__ . '/../../../tests/config/services.yml'); + $this->container = (new ContainerFactory)->create(); $this->fileReconstructor = $this->container->get(FileReconstructor::class); } diff --git a/tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php b/tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php deleted file mode 100644 index c9e5e5bcece..00000000000 --- a/tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php +++ /dev/null @@ -1,23 +0,0 @@ -