From daaf2143d8079ce50915960622f3ed747c1bcc67 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Thu, 18 Jun 2020 17:42:43 +0200 Subject: [PATCH] skip already correct group --- rules/autodiscovery/src/FileMover/FileMover.php | 6 ++++++ ...nterfacesToContractNamespaceDirectoryRectorTest.php | 8 ++++++++ .../Source/Contract/Fixture/RandomInterface.php | 10 ---------- .../Source/Contract/KeepThisSomeInterface.php | 10 ++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) delete mode 100644 rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Source/Contract/Fixture/RandomInterface.php create mode 100644 rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Source/Contract/KeepThisSomeInterface.php diff --git a/rules/autodiscovery/src/FileMover/FileMover.php b/rules/autodiscovery/src/FileMover/FileMover.php index b06f04d85e7..0d60ef382ed 100644 --- a/rules/autodiscovery/src/FileMover/FileMover.php +++ b/rules/autodiscovery/src/FileMover/FileMover.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Rector\Autodiscovery\FileMover; +use Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; @@ -60,6 +61,11 @@ final class FileMover $currentClassName = $currentNamespace->name->toString() . '\\' . $smartFileInfo->getBasenameWithoutSuffix(); + // is already in the right group + if (Strings::endsWith((string) $currentNamespace->name, '\\' . $desiredGroupName)) { + return null; + } + // change namespace to new one $newNamespaceName = $this->createNewNamespaceName($desiredGroupName, $currentNamespace); $newClassName = $this->createNewClassName($smartFileInfo, $newNamespaceName); diff --git a/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php b/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php index c3f98bfdfab..0d1a28319ae 100644 --- a/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php +++ b/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/MoveInterfacesToContractNamespaceDirectoryRectorTest.php @@ -42,6 +42,14 @@ final class MoveInterfacesToContractNamespaceDirectoryRectorTest extends Abstrac $this->getFixtureTempDirectory() . '/Source/Control/FormFactory.php', __DIR__ . '/Source/Control/FormFactory.php', ]; + + // skip already in correct location + yield [ + __DIR__ . '/Source/Contract/KeepThisSomeInterface.php', + $this->getFixtureTempDirectory() . '/Source/Contract/KeepThisSomeInterface.php', + // no change + __DIR__ . '/Source/Contract/KeepThisSomeInterface.php', + ]; } protected function getRectorClass(): string diff --git a/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Source/Contract/Fixture/RandomInterface.php b/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Source/Contract/Fixture/RandomInterface.php deleted file mode 100644 index 0ec5dd26f6b..00000000000 --- a/rules/autodiscovery/tests/Rector/FileSystem/MoveInterfacesToContractNamespaceDirectoryRector/Source/Contract/Fixture/RandomInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -