Updated Rector to commit 32510e0dc7ee63d5a38c7d088aaf82eee605c516

32510e0dc7 Remove array items directly RemoveDuplicatedArrayKeyRector (#4013)
This commit is contained in:
Tomas Votruba 2023-05-29 09:16:46 +00:00
parent c98c306aa8
commit 601ac11f14
5 changed files with 38 additions and 25 deletions

View File

@ -66,21 +66,25 @@ CODE_SAMPLE
*/ */
public function refactor(Node $node) : ?Node public function refactor(Node $node) : ?Node
{ {
$arrayItemsWithDuplicatedKey = $this->getArrayItemsWithDuplicatedKey($node); $duplicatedKeysArrayItems = $this->resolveDuplicateKeysArrayItems($node);
if ($arrayItemsWithDuplicatedKey === []) { if ($duplicatedKeysArrayItems === []) {
return null; return null;
} }
foreach ($arrayItemsWithDuplicatedKey as $arrayItemWithDuplicatedKey) { foreach ($node->items as $key => $arrayItem) {
// keep last item if (!$arrayItem instanceof ArrayItem) {
\array_pop($arrayItemWithDuplicatedKey); continue;
$this->nodeRemover->removeNodes($arrayItemWithDuplicatedKey); }
if (!$this->isArrayItemDuplicated($duplicatedKeysArrayItems, $arrayItem)) {
continue;
}
unset($node->items[$key]);
} }
return $node; return $node;
} }
/** /**
* @return ArrayItem[][] * @return ArrayItem[]
*/ */
private function getArrayItemsWithDuplicatedKey(Array_ $array) : array private function resolveDuplicateKeysArrayItems(Array_ $array) : array
{ {
$arrayItemsByKeys = []; $arrayItemsByKeys = [];
foreach ($array->items as $arrayItem) { foreach ($array->items as $arrayItem) {
@ -96,12 +100,12 @@ CODE_SAMPLE
return $this->filterItemsWithSameKey($arrayItemsByKeys); return $this->filterItemsWithSameKey($arrayItemsByKeys);
} }
/** /**
* @param ArrayItem[][] $arrayItemsByKeys * @param array<mixed, ArrayItem[]> $arrayItemsByKeys
* @return ArrayItem[][] * @return array<ArrayItem>
*/ */
private function filterItemsWithSameKey(array $arrayItemsByKeys) : array private function filterItemsWithSameKey(array $arrayItemsByKeys) : array
{ {
$result = []; $duplicatedArrayItems = [];
foreach ($arrayItemsByKeys as $arrayItems) { foreach ($arrayItemsByKeys as $arrayItems) {
if (\count($arrayItems) <= 1) { if (\count($arrayItems) <= 1) {
continue; continue;
@ -112,8 +116,17 @@ CODE_SAMPLE
if ($this->multiInstanceofChecker->isInstanceOf($currentArrayItemKey, self::ALLOWED_KEY_DUPLICATES)) { if ($this->multiInstanceofChecker->isInstanceOf($currentArrayItemKey, self::ALLOWED_KEY_DUPLICATES)) {
continue; continue;
} }
$result[] = $arrayItems; // keep last one
\array_pop($arrayItems);
$duplicatedArrayItems = \array_merge($duplicatedArrayItems, $arrayItems);
} }
return $result; return $duplicatedArrayItems;
}
/**
* @param ArrayItem[] $duplicatedKeysArrayItems
*/
private function isArrayItemDuplicated(array $duplicatedKeysArrayItems, ArrayItem $arrayItem) : bool
{
return \in_array($arrayItem, $duplicatedKeysArrayItems, \true);
} }
} }

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = 'cd48bfcc4785fb0d2cf828240f8f71231b232c85'; public const PACKAGE_VERSION = '32510e0dc7ee63d5a38c7d088aaf82eee605c516';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2023-05-29 08:35:20'; public const RELEASE_DATE = '2023-05-29 09:12:48';
/** /**
* @var int * @var int
*/ */

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155::getLoader(); return ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155 class ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f
{ {
private static $loader; private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitf1683014dc82e46c87167ac2cba04155::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::getInitializer($loader));
$loader->setClassMapAuthoritative(true); $loader->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$files; $filesToLoad = \Composer\Autoload\ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) { $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInitf1683014dc82e46c87167ac2cba04155 class ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3083,9 +3083,9 @@ class ComposerStaticInitf1683014dc82e46c87167ac2cba04155
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$classMap; $loader->classMap = ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }