Skip to content

Commit

Permalink
[CodingStyle] Move ArraySpreadInsteadOfArrayMergeRector from php74 to…
Browse files Browse the repository at this point in the history
… codingstyle sets list (#5230)

* [CodingStyle] Move ArraySpreadInsteadOfArrayMergeRector from php74 to codingstyle sets list

* regenerate docs
  • Loading branch information
samsonasik committed Nov 7, 2023
1 parent bd191f0 commit 9adc7a0
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 74 deletions.
56 changes: 28 additions & 28 deletions build/target-repository/docs/rector_rules_overview.md
Expand Up @@ -8,7 +8,7 @@

- [CodeQuality](#codequality) (72)

- [CodingStyle](#codingstyle) (28)
- [CodingStyle](#codingstyle) (29)

- [DeadCode](#deadcode) (42)

Expand Down Expand Up @@ -36,7 +36,7 @@

- [Php73](#php73) (9)

- [Php74](#php74) (13)
- [Php74](#php74) (12)

- [Php80](#php80) (16)

Expand Down Expand Up @@ -1597,6 +1597,32 @@ Adds array default value to property to prevent foreach over null error

<br>

### 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];
}
}
```

<br>

### BinarySwitchToIfElseRector

Changes switch with 2 options to if-else
Expand Down Expand Up @@ -4483,32 +4509,6 @@ Change `array_key_exists()` on property to `property_exists()`

<br>

### 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];
}
}
```

<br>

### ClosureToArrowFunctionRector

Change closure to arrow function
Expand Down
2 changes: 2 additions & 0 deletions config/set/coding-style.php
Expand Up @@ -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;
Expand Down Expand Up @@ -71,5 +72,6 @@
SplitGroupedPropertiesRector::class,
SplitGroupedClassConstantsRector::class,
ExplicitPublicClassMethodRector::class,
ArraySpreadInsteadOfArrayMergeRector::class,
]);
};
1 change: 0 additions & 1 deletion phpstan.neon
Expand Up @@ -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#'
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class DemoFile
{
Expand All @@ -14,7 +14,7 @@ final class DemoFile
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class DemoFile
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class DemoFile
{
Expand All @@ -16,7 +16,7 @@ final class DemoFile
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class DemoFile
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class DemoFile
{
Expand All @@ -16,7 +16,7 @@ final class DemoFile
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class DemoFile
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

class IntegerKeys
{
Expand All @@ -17,7 +17,7 @@ class IntegerKeys
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

class IntegerKeys
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

use Symfony\Component\Finder\Finder;

Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

final class SkipIteratorToArray
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

class SkipParseUrl
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

class SkipSimpleArrayMerge
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

use stdClass;

Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

class SkipStringKeys
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;

function x(): array
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class AnyKey
{
Expand Down Expand Up @@ -33,7 +33,7 @@ class AnyKey
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class AnyKey
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class DemoFile
{
Expand All @@ -14,7 +14,7 @@ final class DemoFile
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class DemoFile
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class DemoFile
{
Expand All @@ -16,7 +16,7 @@ final class DemoFile
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class DemoFile
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class DemoFile
{
Expand All @@ -16,7 +16,7 @@ final class DemoFile
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class DemoFile
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class IntegerKeys
{
Expand All @@ -17,7 +17,7 @@ class IntegerKeys
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class IntegerKeys
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class ParseUrl
{
Expand All @@ -23,7 +23,7 @@ class ParseUrl
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class ParseUrl
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class SkipFirstClassCallable
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

use Symfony\Component\Finder\Finder;

Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

final class SkipIteratorToArray
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp74;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class SkipSimpleArrayMerge
{
Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

use stdClass;

Expand Down
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class StringKeys
{
Expand All @@ -24,7 +24,7 @@ class StringKeys
-----
<?php

namespace Rector\Tests\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;
namespace Rector\Tests\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector\FixturePhp81;

class StringKeys
{
Expand Down

0 comments on commit 9adc7a0

Please sign in to comment.