From 1d5d0dd30baeec9c3544cca8c025689391449ad4 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 16 Nov 2023 14:51:30 +0000 Subject: [PATCH] Updated Rector to commit 1595e34d12d856eab8e2478de357f0b1dff3556f https://github.com/rectorphp/rector-src/commit/1595e34d12d856eab8e2478de357f0b1dff3556f [CodingStyle] Refactor UseImportsAdder to return [FileWithoutNamespace] code on no namespaced code (#5254) --- packages/PostRector/Rector/NameImportingPostRector.php | 7 +------ rules/CodingStyle/Application/UseImportsAdder.php | 6 +++--- src/Application/VersionResolver.php | 4 ++-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/PostRector/Rector/NameImportingPostRector.php b/packages/PostRector/Rector/NameImportingPostRector.php index fca0387d72b1..d932732ad939 100644 --- a/packages/PostRector/Rector/NameImportingPostRector.php +++ b/packages/PostRector/Rector/NameImportingPostRector.php @@ -120,13 +120,8 @@ private function processNodeName(Name $name, File $file) : ?Node return null; } $namespaces = \array_filter($file->getNewStmts(), static function (Stmt $stmt) : bool { - return $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace; + return $stmt instanceof Namespace_; }); - // handle overlapped resolve last new stmts - // @see https://github.com/rectorphp/rector-src/pull/5251 - if ($namespaces === []) { - return null; - } if (\count($namespaces) > 1) { return null; } diff --git a/rules/CodingStyle/Application/UseImportsAdder.php b/rules/CodingStyle/Application/UseImportsAdder.php index 4bed4c783a32..14104606e148 100644 --- a/rules/CodingStyle/Application/UseImportsAdder.php +++ b/rules/CodingStyle/Application/UseImportsAdder.php @@ -52,7 +52,7 @@ public function addImportsToStmts(FileWithoutNamespace $fileWithoutNamespace, ar $functionUseImportTypes = $this->diffFullyQualifiedObjectTypes($functionUseImportTypes, $existingFunctionUseImports); $newUses = $this->createUses($useImportTypes, $constantUseImportTypes, $functionUseImportTypes, null); if ($newUses === []) { - return $stmts; + return [$fileWithoutNamespace]; } // place after declare strict_types foreach ($stmts as $key => $stmt) { @@ -67,14 +67,14 @@ public function addImportsToStmts(FileWithoutNamespace $fileWithoutNamespace, ar \array_splice($stmts, $key + 1, 0, $nodesToAdd); $fileWithoutNamespace->stmts = $stmts; $fileWithoutNamespace->stmts = \array_values($fileWithoutNamespace->stmts); - return $fileWithoutNamespace->stmts; + return [$fileWithoutNamespace]; } } $this->mirrorUseComments($stmts, $newUses); // make use stmts first $fileWithoutNamespace->stmts = \array_merge($newUses, $stmts); $fileWithoutNamespace->stmts = \array_values($fileWithoutNamespace->stmts); - return $fileWithoutNamespace->stmts; + return [$fileWithoutNamespace]; } /** * @param FullyQualifiedObjectType[] $useImportTypes diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index e7d172863ccb..c6588ac17736 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '60047ce7785545401ad870d483060ce640fa3369'; + public const PACKAGE_VERSION = '1595e34d12d856eab8e2478de357f0b1dff3556f'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-11-16 12:34:15'; + public const RELEASE_DATE = '2023-11-16 21:49:13'; /** * @var int */