From 9adc7a04b3a312957bb305edafcd0427fa6bd257 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 8 Nov 2023 01:54:33 +0700 Subject: [PATCH] [CodingStyle] Move ArraySpreadInsteadOfArrayMergeRector from php74 to codingstyle sets list (#5230) * [CodingStyle] Move ArraySpreadInsteadOfArrayMergeRector from php74 to codingstyle sets list * regenerate docs --- .../docs/rector_rules_overview.md | 56 +++++++++---------- config/set/coding-style.php | 2 + phpstan.neon | 1 - ..._explicit_array_and_explicit_array.php.inc | 4 +- ...latten_explicit_array_and_variable.php.inc | 4 +- ...latten_variable_and_explicit_array.php.inc | 4 +- .../FixturePhp74}/integer_keys.php.inc | 4 +- .../FixturePhp74}/skip_get_iterator.php.inc | 2 +- .../skip_iterator_to_array.php.inc | 2 +- .../FixturePhp74/skip_parse_url.php.inc | 2 +- .../skip_simple_array_merge.php.inc | 2 +- .../skip_spread_array_merge.php.inc | 2 +- .../FixturePhp74/skip_string_keys.php.inc | 2 +- .../skip_string_keys_from_functions.php.inc | 2 +- .../FixturePhp81/any_key.php.inc | 4 +- ..._explicit_array_and_explicit_array.php.inc | 4 +- ...latten_explicit_array_and_variable.php.inc | 4 +- ...latten_variable_and_explicit_array.php.inc | 4 +- .../FixturePhp81}/integer_keys.php.inc | 4 +- .../FixturePhp81/parse_url.php.inc | 4 +- .../skip_first_class_callable.php.inc | 2 +- .../FixturePhp81}/skip_get_iterator.php.inc | 2 +- .../skip_iterator_to_array.php.inc | 2 +- .../skip_simple_array_merge.php.inc | 2 +- .../skip_spread_array_merge.php.inc | 2 +- .../FixturePhp81/string_keys.php.inc | 4 +- .../string_keys_from_functions.php.inc | 4 +- ...raySpreadInsteadOfArrayMergeRectorTest.php | 2 +- ...raySpreadInsteadOfArrayMergeRectorTest.php | 2 +- .../config/configured_rule_php74.php | 2 +- .../config/configured_rule_php81.php | 2 +- .../ArraySpreadInsteadOfArrayMergeRector.php | 6 +- utils/Command/MissingInSetCommand.php | 2 - 33 files changed, 73 insertions(+), 74 deletions(-) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc (53%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_variable.php.inc (58%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_variable_and_explicit_array.php.inc (58%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74}/integer_keys.php.inc (66%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74}/skip_get_iterator.php.inc (71%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74}/skip_iterator_to_array.php.inc (57%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/skip_parse_url.php.inc (77%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74}/skip_simple_array_merge.php.inc (57%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/skip_spread_array_merge.php.inc (72%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/skip_string_keys.php.inc (80%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/skip_string_keys_from_functions.php.inc (67%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/any_key.php.inc (78%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/flatten_explicit_array_and_explicit_array.php.inc (56%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/flatten_explicit_array_and_variable.php.inc (61%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/flatten_variable_and_explicit_array.php.inc (61%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81}/integer_keys.php.inc (66%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/parse_url.php.inc (77%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/skip_first_class_callable.php.inc (50%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81}/skip_get_iterator.php.inc (71%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81}/skip_iterator_to_array.php.inc (57%) rename rules-tests/{Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74 => CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81}/skip_simple_array_merge.php.inc (57%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/skip_spread_array_merge.php.inc (72%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/string_keys.php.inc (79%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/string_keys_from_functions.php.inc (67%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/Php74ArraySpreadInsteadOfArrayMergeRectorTest.php (87%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/Php81ArraySpreadInsteadOfArrayMergeRectorTest.php (87%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php74.php (79%) rename rules-tests/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php (79%) rename rules/{Php74 => CodingStyle}/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php (94%) diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index a02caed7e16..e8c5154fc95 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -8,7 +8,7 @@ - [CodeQuality](#codequality) (72) -- [CodingStyle](#codingstyle) (28) +- [CodingStyle](#codingstyle) (29) - [DeadCode](#deadcode) (42) @@ -36,7 +36,7 @@ - [Php73](#php73) (9) -- [Php74](#php74) (13) +- [Php74](#php74) (12) - [Php80](#php80) (16) @@ -1597,6 +1597,32 @@ Adds array default value to property to prevent foreach over null error
+### ArraySpreadInsteadOfArrayMergeRector + +Change `array_merge()` to spread operator + +- class: [`Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector`](../rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php) + +```diff + class SomeClass + { + public function run($iter1, $iter2) + { +- $values = array_merge(iterator_to_array($iter1), iterator_to_array($iter2)); ++ $values = [...$iter1, ...$iter2]; + + // Or to generalize to all iterables +- $anotherValues = array_merge( +- is_array($iter1) ? $iter1 : iterator_to_array($iter1), +- is_array($iter2) ? $iter2 : iterator_to_array($iter2) +- ); ++ $anotherValues = [...$iter1, ...$iter2]; + } + } +``` + +
+ ### BinarySwitchToIfElseRector Changes switch with 2 options to if-else @@ -4483,32 +4509,6 @@ Change `array_key_exists()` on property to `property_exists()`
-### ArraySpreadInsteadOfArrayMergeRector - -Change `array_merge()` to spread operator - -- class: [`Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector`](../rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php) - -```diff - class SomeClass - { - public function run($iter1, $iter2) - { -- $values = array_merge(iterator_to_array($iter1), iterator_to_array($iter2)); -+ $values = [...$iter1, ...$iter2]; - - // Or to generalize to all iterables -- $anotherValues = array_merge( -- is_array($iter1) ? $iter1 : iterator_to_array($iter1), -- is_array($iter2) ? $iter2 : iterator_to_array($iter2) -- ); -+ $anotherValues = [...$iter1, ...$iter2]; - } - } -``` - -
- ### ClosureToArrowFunctionRector Change closure to arrow function diff --git a/config/set/coding-style.php b/config/set/coding-style.php index e0c1ad809b2..dcb2a109ecf 100644 --- a/config/set/coding-style.php +++ b/config/set/coding-style.php @@ -14,6 +14,7 @@ use Rector\CodingStyle\Rector\Closure\StaticClosureRector; use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector; +use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector; use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector; use Rector\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector; use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector; @@ -71,5 +72,6 @@ SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class, ExplicitPublicClassMethodRector::class, + ArraySpreadInsteadOfArrayMergeRector::class, ]); }; diff --git a/phpstan.neon b/phpstan.neon index c5b0954c02d..a368c2c6a61 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -528,7 +528,6 @@ parameters: - '#Fetching class constant class of deprecated class Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictConstructorReadonlyClassRector#' - '#Class "Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector" is missing @see annotation with test case class reference#' - '#Register "Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector" service to "php71\.php" config set#' - - '#Register "Rector\\Php74\\Rector\\FuncCall\\ArraySpreadInsteadOfArrayMergeRector" service to "php74\.php" config set#' # dev rule - '#Class "Rector\\Utils\\Rector\\MoveAbstractRectorToChildrenRector" is missing @see annotation with test case class reference#' diff --git a/rules-tests/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc similarity index 53% rename from rules-tests/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc rename to rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc index d3061d77ab7..53bc84db9a3 100644 --- a/rules-tests/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc +++ b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp74/flatten_explicit_array_and_explicit_array.php.inc @@ -1,6 +1,6 @@ phpVersion(PhpVersion::PHP_74); diff --git a/rules-tests/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php similarity index 79% rename from rules-tests/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php rename to rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php index e6dac5cc787..b7af4eab863 100644 --- a/rules-tests/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php +++ b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/config/configured_rule_php81.php @@ -4,7 +4,7 @@ use Rector\Config\RectorConfig; use Rector\Core\ValueObject\PhpVersion; -use Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector; +use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->phpVersion(PhpVersion::PHP_81); diff --git a/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php b/rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php similarity index 94% rename from rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php rename to rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php index f087d4c4906..0b0601e748d 100644 --- a/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php +++ b/rules/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Php74\Rector\FuncCall; +namespace Rector\CodingStyle\Rector\FuncCall; use PhpParser\Node; use PhpParser\Node\Arg; @@ -24,8 +24,8 @@ /** * @changelog https://wiki.php.net/rfc/spread_operator_for_array * - * @see \Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\Php74ArraySpreadInsteadOfArrayMergeRectorTest - * @see \Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\Php81ArraySpreadInsteadOfArrayMergeRectorTest + * @see \Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\Php74ArraySpreadInsteadOfArrayMergeRectorTest + * @see \Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\Php81ArraySpreadInsteadOfArrayMergeRectorTest */ final class ArraySpreadInsteadOfArrayMergeRector extends AbstractRector implements MinPhpVersionInterface { diff --git a/utils/Command/MissingInSetCommand.php b/utils/Command/MissingInSetCommand.php index b15dab867a5..623fedfe0d8 100644 --- a/utils/Command/MissingInSetCommand.php +++ b/utils/Command/MissingInSetCommand.php @@ -8,7 +8,6 @@ use Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Php71\Rector\FuncCall\CountOnNullRector; -use Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector; use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenCollectorRector; use Rector\TypeDeclaration\Rector\BooleanAnd\BinaryOpNullableToInstanceofRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorReadonlyClassRector; @@ -39,7 +38,6 @@ final class MissingInSetCommand extends Command TypedPropertyFromStrictConstructorReadonlyClassRector::class, BinarySwitchToIfElseRector::class, CountOnNullRector::class, - ArraySpreadInsteadOfArrayMergeRector::class, ]; public function __construct(