From 5e6f195e17fc895281e27f02b08cd8fcb980e605 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 8 Mar 2023 15:24:58 +0000 Subject: [PATCH] Updated Rector to commit 291aab4a2afd397cff1a37078b0c5b559f5299de https://github.com/rectorphp/rector-src/commit/291aab4a2afd397cff1a37078b0c5b559f5299de [AutoImport] Add mirror comment support on first Use_ on no namespace code (#3465) --- .../Application/UseImportsAdder.php | 27 ++++++++++++++----- src/Application/VersionResolver.php | 4 +-- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 +++---- vendor/composer/autoload_static.php | 8 +++--- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/rules/CodingStyle/Application/UseImportsAdder.php b/rules/CodingStyle/Application/UseImportsAdder.php index 8e37e5802a7..a170191cb69 100644 --- a/rules/CodingStyle/Application/UseImportsAdder.php +++ b/rules/CodingStyle/Application/UseImportsAdder.php @@ -32,6 +32,23 @@ final class UseImportsAdder $this->usedImportsResolver = $usedImportsResolver; $this->typeFactory = $typeFactory; } + /** + * @param Stmt[] $stmts + * @param Use_[] $newUses + */ + private function mirrorUseComments(array $stmts, array $newUses, int $indexStmt = 0) : void + { + if ($stmts === []) { + return; + } + if ($stmts[$indexStmt] instanceof Use_) { + $comments = (array) $stmts[$indexStmt]->getAttribute(AttributeKey::COMMENTS); + if ($comments !== []) { + $newUses[0]->setAttribute(AttributeKey::COMMENTS, $stmts[$indexStmt]->getAttribute(AttributeKey::COMMENTS)); + $stmts[$indexStmt]->setAttribute(AttributeKey::COMMENTS, null); + } + } + } /** * @param Stmt[] $stmts * @param array $useImportTypes @@ -57,10 +74,12 @@ final class UseImportsAdder // add extra space, if there are no new use imports to be added $nodesToAdd = \array_merge([new Nop()], $newUses); } + $this->mirrorUseComments($stmts, $newUses, $key + 1); \array_splice($stmts, $key + 1, 0, $nodesToAdd); return $stmts; } } + $this->mirrorUseComments($stmts, $newUses); // make use stmts first return \array_merge($newUses, $stmts); } @@ -80,13 +99,7 @@ final class UseImportsAdder if ($newUses === []) { return; } - if ($namespace->stmts[0] instanceof Use_) { - $comments = (array) $namespace->stmts[0]->getAttribute(AttributeKey::COMMENTS); - if ($comments !== []) { - $newUses[0]->setAttribute(AttributeKey::COMMENTS, $namespace->stmts[0]->getAttribute(AttributeKey::COMMENTS)); - $namespace->stmts[0]->setAttribute(AttributeKey::COMMENTS, null); - } - } + $this->mirrorUseComments($namespace->stmts, $newUses); $namespace->stmts = \array_merge($newUses, $namespace->stmts); } /** diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 80b56d400a9..3e9faff7df2 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 = 'ed5caee5b1cdecf12b77b1f2944dde539a3b004f'; + public const PACKAGE_VERSION = '291aab4a2afd397cff1a37078b0c5b559f5299de'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-03-08 14:02:57'; + public const RELEASE_DATE = '2023-03-08 15:18:55'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index d8bed84d027..44432b4da9b 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit87f66dc792c35c6466cef09b5c022d13::getLoader(); +return ComposerAutoloaderInit54753c9f52f143cde46d71a7987471d5::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 3c00f5b5baa..ab45b79f1c6 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit87f66dc792c35c6466cef09b5c022d13 +class ComposerAutoloaderInit54753c9f52f143cde46d71a7987471d5 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit87f66dc792c35c6466cef09b5c022d13 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit87f66dc792c35c6466cef09b5c022d13', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit54753c9f52f143cde46d71a7987471d5', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit87f66dc792c35c6466cef09b5c022d13', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit54753c9f52f143cde46d71a7987471d5', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit87f66dc792c35c6466cef09b5c022d13::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit54753c9f52f143cde46d71a7987471d5::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit87f66dc792c35c6466cef09b5c022d13::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit54753c9f52f143cde46d71a7987471d5::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index a0e4d25d984..76def0c0704 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit87f66dc792c35c6466cef09b5c022d13 +class ComposerStaticInit54753c9f52f143cde46d71a7987471d5 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3133,9 +3133,9 @@ class ComposerStaticInit87f66dc792c35c6466cef09b5c022d13 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit87f66dc792c35c6466cef09b5c022d13::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit87f66dc792c35c6466cef09b5c022d13::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit87f66dc792c35c6466cef09b5c022d13::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit54753c9f52f143cde46d71a7987471d5::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit54753c9f52f143cde46d71a7987471d5::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit54753c9f52f143cde46d71a7987471d5::$classMap; }, null, ClassLoader::class); }