skip already correct group

This commit is contained in:
TomasVotruba 2020-06-18 17:42:43 +02:00
parent 7a85d8596e
commit daaf2143d8
4 changed files with 24 additions and 10 deletions

View File

@ -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);

View File

@ -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

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveEntitiesToEntityDirectoryRector\Source\Contract;
interface RandomInterface
{
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileSystem\MoveInterfacesToContractNamespaceDirectoryRector\Source\Contract;
interface KeepThisSomeInterface
{
}