mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 04:19:44 +01:00
parent
63615f4197
commit
055040f8e8
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
use Rector\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector;
|
||||
use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector;
|
||||
use Rector\DowngradePhp74\Rector\Coalesce\DowngradeNullCoalescingOperatorRector;
|
||||
use Rector\DowngradePhp74\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector;
|
||||
use Rector\DowngradePhp74\Rector\FuncCall\DowngradeStripTagsCallWithArrayRector;
|
||||
use Rector\DowngradePhp74\Rector\LNumber\DowngradeNumericLiteralSeparatorRector;
|
||||
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
|
||||
@ -18,4 +19,5 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services->set(DowngradeNumericLiteralSeparatorRector::class);
|
||||
$services->set(DowngradeStripTagsCallWithArrayRector::class);
|
||||
$services->set(DowngradeArraySpreadRector::class);
|
||||
$services->set(DowngradeArrayMergeCallWithoutArgumentsRector::class);
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
# All 592 Rectors Overview
|
||||
# All 593 Rectors Overview
|
||||
|
||||
- [Projects](#projects)
|
||||
---
|
||||
@ -19,7 +19,7 @@
|
||||
- [DowngradePhp71](#downgradephp71) (3)
|
||||
- [DowngradePhp72](#downgradephp72) (2)
|
||||
- [DowngradePhp73](#downgradephp73) (1)
|
||||
- [DowngradePhp74](#downgradephp74) (6)
|
||||
- [DowngradePhp74](#downgradephp74) (7)
|
||||
- [DowngradePhp80](#downgradephp80) (6)
|
||||
- [DynamicTypeAnalysis](#dynamictypeanalysis) (3)
|
||||
- [FileSystemRector](#filesystemrector) (1)
|
||||
@ -5072,6 +5072,29 @@ Replace arrow functions with anonymous functions
|
||||
|
||||
<br><br>
|
||||
|
||||
### `DowngradeArrayMergeCallWithoutArgumentsRector`
|
||||
|
||||
- class: [`Rector\DowngradePhp74\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector`](/rules/downgrade-php74/src/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php)
|
||||
- [test fixtures](/rules/downgrade-php74/tests/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector/Fixture)
|
||||
|
||||
Add missing param to `array_merge` and `array_merge_recursive`
|
||||
|
||||
```diff
|
||||
class SomeClass
|
||||
{
|
||||
- public function run()
|
||||
+ public function run()
|
||||
{
|
||||
- array_merge();
|
||||
- array_merge_recursive();
|
||||
+ array_merge([]);
|
||||
+ array_merge_recursive([]);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br><br>
|
||||
|
||||
### `DowngradeArraySpreadRector`
|
||||
|
||||
- class: [`Rector\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector`](/rules/downgrade-php74/src/Rector/Array_/DowngradeArraySpreadRector.php)
|
||||
|
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp74\Rector\FuncCall;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Arg;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
use Rector\Core\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\DowngradeArrayMergeCallWithoutArgumentsRectorTest
|
||||
*/
|
||||
final class DowngradeArrayMergeCallWithoutArgumentsRector extends AbstractRector
|
||||
{
|
||||
public function getDefinition(): RectorDefinition
|
||||
{
|
||||
return new RectorDefinition('Add missing param to `array_merge` and `array_merge_recursive`', [
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
array_merge();
|
||||
array_merge_recursive();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
array_merge([]);
|
||||
array_merge_recursive([]);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [FuncCall::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FuncCall $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->shouldRefactor($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$node->args = [new Arg(new Array_())];
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function shouldRefactor(FuncCall $funcCall): bool
|
||||
{
|
||||
if (! $this->isNames($funcCall, ['array_merge', 'array_merge_recursive'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If param is provided, do nothing
|
||||
if ($funcCall->args !== []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Rector\Core\ValueObject\PhpVersionFeature;
|
||||
use Rector\DowngradePhp74\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class DowngradeArrayMergeCallWithoutArgumentsRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @requires PHP 7.4
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return DowngradeArrayMergeCallWithoutArgumentsRector::class;
|
||||
}
|
||||
|
||||
protected function getPhpVersion(): string
|
||||
{
|
||||
return PhpVersionFeature::BEFORE_STRIP_TAGS_WITH_ARRAY;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class ArrayMergeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
array_merge();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class ArrayMergeClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
array_merge([]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class ArrayMergeRecursiveClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
array_merge_recursive();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class ArrayMergeRecursiveClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
array_merge_recursive([]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class SkipArrayClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// Array: do no change
|
||||
array_merge([]);
|
||||
array_merge_recursive([]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class SkipMultipleArgumentsClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$array = [];
|
||||
// Multiple Arguments: do no change
|
||||
array_merge([], []);
|
||||
array_merge($array, []);
|
||||
array_merge([], $array);
|
||||
array_merge($array, $array);
|
||||
array_merge_recursive([], []);
|
||||
array_merge_recursive($array, []);
|
||||
array_merge_recursive([], $array);
|
||||
array_merge_recursive($array, $array);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\DowngradePhp74\Tests\Rector\FuncCall\DowngradeArrayMergeCallWithoutArgumentsRector\Fixture;
|
||||
|
||||
class SkipVariableClass
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$array = [];
|
||||
// Variable: do no change
|
||||
array_merge($array);
|
||||
array_merge_recursive($array);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -226,4 +226,9 @@ final class PhpVersionFeature
|
||||
* @var string
|
||||
*/
|
||||
public const IS_ITERABLE = '7.1';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const BEFORE_ARRAY_MERGE_WITHOUT_ARGUMENTS = '7.3';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user