From dae17c98a0375898c5223eae06ba979d678959a7 Mon Sep 17 00:00:00 2001 From: Dorian Villet Date: Thu, 3 Oct 2019 00:50:05 +0200 Subject: [PATCH] Check for root namespace class differently. --- .../Rector/Namespace_/ImportFullyQualifiedNamesRector.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php b/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php index cf3b7989e6a..0aeb0615b64 100644 --- a/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php +++ b/packages/CodingStyle/src/Rector/Namespace_/ImportFullyQualifiedNamesRector.php @@ -2,6 +2,7 @@ namespace Rector\CodingStyle\Rector\Namespace_; +use Nette\Utils\Strings; use PhpParser\Node; use PhpParser\Node\Name; use Rector\CodingStyle\Node\NameImporter; @@ -82,8 +83,11 @@ PHP public function refactor(Node $node): ?Node { // Importing root namespace classes (like \DateTime) is optional - if (!$this->shouldImportRootNamespaceClasses && $node instanceof Name && !$node->isQualified()) { - return null; + if (! $this->shouldImportRootNamespaceClasses) { + $name = $this->getName($node); + if (Strings::startsWith($name, '\\') && substr_count($name, '\\') === 1) { + return null; + } } $this->useAddingCommander->analyseFileInfoUseStatements($node);