mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit 32510e0dc7ee63d5a38c7d088aaf82eee605c516
32510e0dc7
Remove array items directly RemoveDuplicatedArrayKeyRector (#4013)
This commit is contained in:
parent
c98c306aa8
commit
601ac11f14
@ -66,21 +66,25 @@ CODE_SAMPLE
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$arrayItemsWithDuplicatedKey = $this->getArrayItemsWithDuplicatedKey($node);
|
||||
if ($arrayItemsWithDuplicatedKey === []) {
|
||||
$duplicatedKeysArrayItems = $this->resolveDuplicateKeysArrayItems($node);
|
||||
if ($duplicatedKeysArrayItems === []) {
|
||||
return null;
|
||||
}
|
||||
foreach ($arrayItemsWithDuplicatedKey as $arrayItemWithDuplicatedKey) {
|
||||
// keep last item
|
||||
\array_pop($arrayItemWithDuplicatedKey);
|
||||
$this->nodeRemover->removeNodes($arrayItemWithDuplicatedKey);
|
||||
foreach ($node->items as $key => $arrayItem) {
|
||||
if (!$arrayItem instanceof ArrayItem) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->isArrayItemDuplicated($duplicatedKeysArrayItems, $arrayItem)) {
|
||||
continue;
|
||||
}
|
||||
unset($node->items[$key]);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @return ArrayItem[][]
|
||||
* @return ArrayItem[]
|
||||
*/
|
||||
private function getArrayItemsWithDuplicatedKey(Array_ $array) : array
|
||||
private function resolveDuplicateKeysArrayItems(Array_ $array) : array
|
||||
{
|
||||
$arrayItemsByKeys = [];
|
||||
foreach ($array->items as $arrayItem) {
|
||||
@ -96,12 +100,12 @@ CODE_SAMPLE
|
||||
return $this->filterItemsWithSameKey($arrayItemsByKeys);
|
||||
}
|
||||
/**
|
||||
* @param ArrayItem[][] $arrayItemsByKeys
|
||||
* @return ArrayItem[][]
|
||||
* @param array<mixed, ArrayItem[]> $arrayItemsByKeys
|
||||
* @return array<ArrayItem>
|
||||
*/
|
||||
private function filterItemsWithSameKey(array $arrayItemsByKeys) : array
|
||||
{
|
||||
$result = [];
|
||||
$duplicatedArrayItems = [];
|
||||
foreach ($arrayItemsByKeys as $arrayItems) {
|
||||
if (\count($arrayItems) <= 1) {
|
||||
continue;
|
||||
@ -112,8 +116,17 @@ CODE_SAMPLE
|
||||
if ($this->multiInstanceofChecker->isInstanceOf($currentArrayItemKey, self::ALLOWED_KEY_DUPLICATES)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'cd48bfcc4785fb0d2cf828240f8f71231b232c85';
|
||||
public const PACKAGE_VERSION = '32510e0dc7ee63d5a38c7d088aaf82eee605c516';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-29 08:35:20';
|
||||
public const RELEASE_DATE = '2023-05-29 09:12:48';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155::getLoader();
|
||||
return ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155
|
||||
class ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155
|
||||
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__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitf1683014dc82e46c87167ac2cba04155', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit308338dff866dd8edbacc93b1ecfa91f', 'loadClassLoader'));
|
||||
|
||||
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->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitf1683014dc82e46c87167ac2cba04155
|
||||
class ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3083,9 +3083,9 @@ class ComposerStaticInitf1683014dc82e46c87167ac2cba04155
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitf1683014dc82e46c87167ac2cba04155::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit308338dff866dd8edbacc93b1ecfa91f::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user