-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SwapMethodCallArgumentsRector (#3726)
* ✨ add SwapMethodCallArgumentsRector * Update rules/Arguments/Rector/MethodCall/SwapMethodCallArgumentsRector.php Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> * Clean up --------- Co-authored-by: Tomas Votruba <tomas.vot@gmail.com> Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
- Loading branch information
1 parent
c6cb214
commit 575e799
Showing
11 changed files
with
439 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ts/Arguments/Rector/MethodCall/SwapMethodCallArgumentsRector/Fixture/dynamic_call.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class Fixture | ||
{ | ||
public function run(MethodCaller $caller) | ||
{ | ||
$caller->someCall($one, $two, $three); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class Fixture | ||
{ | ||
public function run(MethodCaller $caller) | ||
{ | ||
$caller->someCall($three, $two, $one); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...or/MethodCall/SwapMethodCallArgumentsRector/Fixture/dynamic_call_immediate_return.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class Fixture | ||
{ | ||
public function run(MethodCaller $caller) | ||
{ | ||
return $caller->someCall($one, $two, $three); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class Fixture | ||
{ | ||
public function run(MethodCaller $caller) | ||
{ | ||
return $caller->someCall($three, $two, $one); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...s/Rector/MethodCall/SwapMethodCallArgumentsRector/Fixture/static_call_with_parent.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class ParentCall extends MethodCaller | ||
{ | ||
public function run() | ||
{ | ||
parent::someCall($one, $two, $three); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class ParentCall extends MethodCaller | ||
{ | ||
public function run() | ||
{ | ||
parent::someCall($three, $two, $one); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...nts/Rector/MethodCall/SwapMethodCallArgumentsRector/Fixture/static_call_with_self.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class SelfCall extends MethodCaller | ||
{ | ||
public function run() | ||
{ | ||
self::someCall($one, $two, $three); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
final class SelfCall extends MethodCaller | ||
{ | ||
public function run() | ||
{ | ||
self::someCall($three, $two, $one); | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...s/Rector/MethodCall/SwapMethodCallArgumentsRector/Fixture/static_call_with_static.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
class StaticCall extends MethodCaller | ||
{ | ||
public function run() | ||
{ | ||
static::someCall($one, $two, $three); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Fixture; | ||
|
||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
class StaticCall extends MethodCaller | ||
{ | ||
public function run() | ||
{ | ||
static::someCall($three, $two, $one); | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...s-tests/Arguments/Rector/MethodCall/SwapMethodCallArgumentsRector/Source/MethodCaller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source; | ||
|
||
class MethodCaller | ||
{ | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...nts/Rector/MethodCall/SwapMethodCallArgumentsRector/SwapMethodCallArgumentsRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class SwapMethodCallArgumentsRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
foreach (self::yieldFilesFromDirectory(__DIR__ . '/Fixture') as $filePath) { | ||
yield basename($filePath[0]) => $filePath; | ||
} | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ests/Arguments/Rector/MethodCall/SwapMethodCallArgumentsRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector; | ||
use Rector\Arguments\ValueObject\SwapMethodCallArguments; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Tests\Arguments\Rector\MethodCall\SwapMethodCallArgumentsRector\Source\MethodCaller; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->ruleWithConfiguration(SwapMethodCallArgumentsRector::class, [ | ||
new SwapMethodCallArguments(MethodCaller::class, 'someCall', [2, 1, 0]), | ||
]); | ||
}; |
Oops, something went wrong.