From 185eedb9e4765d1ef3d925c4125e5c751efcf223 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 7 Oct 2017 22:05:33 +0200 Subject: [PATCH 1/2] fix NamespaceReplacerRector order --- src/Rector/Dynamic/NamespaceReplacerRector.php | 3 +++ tests/Rector/Dynamic/NamespaceReplacerRector/config/rector.yml | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Rector/Dynamic/NamespaceReplacerRector.php b/src/Rector/Dynamic/NamespaceReplacerRector.php index 6a741e50319..b6d272dfdc6 100644 --- a/src/Rector/Dynamic/NamespaceReplacerRector.php +++ b/src/Rector/Dynamic/NamespaceReplacerRector.php @@ -24,6 +24,8 @@ final class NamespaceReplacerRector extends AbstractRector */ public function __construct(array $oldToNewNamespaces) { + krsort($oldToNewNamespaces); + $this->oldToNewNamespaces = $oldToNewNamespaces; } @@ -116,6 +118,7 @@ final class NamespaceReplacerRector extends AbstractRector private function getNewNamespaceForOldOne(string $namespace): array { foreach ($this->oldToNewNamespaces as $oldNamespace => $newNamespace) { + // ... if (Strings::startsWith($namespace, $oldNamespace)) { return [$oldNamespace, $newNamespace]; } diff --git a/tests/Rector/Dynamic/NamespaceReplacerRector/config/rector.yml b/tests/Rector/Dynamic/NamespaceReplacerRector/config/rector.yml index 865389a78fd..7485ee68474 100644 --- a/tests/Rector/Dynamic/NamespaceReplacerRector/config/rector.yml +++ b/tests/Rector/Dynamic/NamespaceReplacerRector/config/rector.yml @@ -1,5 +1,4 @@ rectors: Rector\Rector\Dynamic\NamespaceReplacerRector: - # todo: add autosort to make complex first; allows reverse order - 'OldNamespaceWith\OldSplitNamespace': 'NewNamespaceWith\NewSplitNamespace' 'OldNamespace': 'NewNamespace' + 'OldNamespaceWith\OldSplitNamespace': 'NewNamespaceWith\NewSplitNamespace' From 5cefeab9af4553095d9a4de3281bc8c35ba31255 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 7 Oct 2017 22:15:33 +0200 Subject: [PATCH 2/2] cleanup --- src/Rector/Dynamic/NamespaceReplacerRector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Rector/Dynamic/NamespaceReplacerRector.php b/src/Rector/Dynamic/NamespaceReplacerRector.php index b6d272dfdc6..bf26a03b46a 100644 --- a/src/Rector/Dynamic/NamespaceReplacerRector.php +++ b/src/Rector/Dynamic/NamespaceReplacerRector.php @@ -118,7 +118,6 @@ final class NamespaceReplacerRector extends AbstractRector private function getNewNamespaceForOldOne(string $namespace): array { foreach ($this->oldToNewNamespaces as $oldNamespace => $newNamespace) { - // ... if (Strings::startsWith($namespace, $oldNamespace)) { return [$oldNamespace, $newNamespace]; }