Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Renaming] New Rule: RenameFunctionLikeParamWithinCallLikeArgRector (#…
…5554) * working * Code quality refactor * Docs * Fixes PHPDoc @see tag * Rename of Rule * Reset hasChanged property Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> * Handle first class callable * stop transversal upon finding a use * Update rule description * Refactored to use built in services * Fixes * fixes * replace isset with null coalescing Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com> --------- Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
- Loading branch information
1 parent
f9b3312
commit 4951acc
Showing
12 changed files
with
530 additions
and
8 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
57 changes: 57 additions & 0 deletions
57
...ector/FunctionLike/RenameFunctionLikeParamWithinCallLikeArgRector/Fixture/fixture.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,57 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
use SomeNamespace\SomeClass; | ||
use SomeNamespace\SomeClassForNamed; | ||
|
||
function fixture() | ||
{ | ||
SomeClass::someCall(function ($qryOne) { | ||
return $qryOne; | ||
}); | ||
|
||
$varOne = new SomeClass(); | ||
$varOne->someCall(function ($qryTwo) { | ||
return $qryTwo; | ||
}); | ||
|
||
(new SomeClass())->someCall(function ($qryThree) { | ||
return $qryThree; | ||
}); | ||
|
||
$varOne->someCall(fn($qryFour) => $qryFour); | ||
|
||
SomeClassForNamed::someCall('a', 'b', callback: fn($varTwo) => $varTwo); | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
use SomeNamespace\SomeClass; | ||
use SomeNamespace\SomeClassForNamed; | ||
|
||
function fixture() | ||
{ | ||
SomeClass::someCall(function ($query) { | ||
return $query; | ||
}); | ||
|
||
$varOne = new SomeClass(); | ||
$varOne->someCall(function ($query) { | ||
return $query; | ||
}); | ||
|
||
(new SomeClass())->someCall(function ($query) { | ||
return $query; | ||
}); | ||
|
||
$varOne->someCall(fn($query) => $query); | ||
|
||
SomeClassForNamed::someCall('a', 'b', callback: fn($query) => $query); | ||
} | ||
|
||
?> |
39 changes: 39 additions & 0 deletions
39
...FunctionLikeParamWithinCallLikeArgRector/Fixture/skip_conflicting_parameter_names.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,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
use SomeNamespace\SomeClass; | ||
use SomeNamespace\SomeClassForNamed; | ||
|
||
function skip_conflicting_parameter_names() | ||
{ | ||
SomeClass::someCall(function ($qry, $query) { | ||
return $qry; | ||
}); | ||
|
||
SomeClass::someCall(fn ($qry, $query) => $qry); | ||
|
||
SomeClass::someCall(function ($qry, $query) { | ||
echo $query; | ||
return $qry; | ||
}); | ||
|
||
$query = 'a'; | ||
|
||
SomeClass::someCall(function ($qry) use ($query) { | ||
return $query; | ||
}); | ||
|
||
SomeClass::someCall(function ($qry) use ($query) { | ||
return $qry; | ||
}); | ||
|
||
SomeClass::someCall(function ($qryFive) { | ||
echo $qryFive; | ||
return function ($query) { | ||
return $query; | ||
}; | ||
}); | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...ke/RenameFunctionLikeParamWithinCallLikeArgRector/Fixture/skip_missing_parameters.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,10 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
use SomeNamespace\SomeClass; | ||
|
||
SomeClass::someOtherCall('a', function () { | ||
}); | ||
|
||
?> |
11 changes: 11 additions & 0 deletions
11
...RenameFunctionLikeParamWithinCallLikeArgRector/Fixture/skip_non_function_like_arg.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
use SomeNamespace\SomeClass; | ||
|
||
SomeClass::someOtherCall('a', function ($qry) { | ||
return $qry; | ||
}); | ||
|
||
?> |
9 changes: 9 additions & 0 deletions
9
...ke/RenameFunctionLikeParamWithinCallLikeArgRector/Fixture/skip_non_matching_class.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,9 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
SomeOtherClass::someCall(function ($qry) { | ||
return $qry; | ||
}); | ||
|
||
?> |
11 changes: 11 additions & 0 deletions
11
...e/RenameFunctionLikeParamWithinCallLikeArgRector/Fixture/skip_non_matching_method.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,11 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector\Fixture; | ||
|
||
use SomeNamespace\SomeClass; | ||
|
||
SomeClass::someOtherCall(function ($qry) { | ||
return $qry; | ||
}); | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
...onLikeParamWithinCallLikeArgRector/RenameFunctionLikeParamWithinCallLikeArgRectorTest.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class RenameFunctionLikeParamWithinCallLikeArgRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...or/FunctionLike/RenameFunctionLikeParamWithinCallLikeArgRector/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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Renaming\Rector\FunctionLike\RenameFunctionLikeParamWithinCallLikeArgRector; | ||
use Rector\Renaming\ValueObject\RenameFunctionLikeParamWithinCallLikeArg; | ||
use Rector\ValueObject\PhpVersionFeature; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig | ||
->ruleWithConfiguration(RenameFunctionLikeParamWithinCallLikeArgRector::class, [ | ||
new RenameFunctionLikeParamWithinCallLikeArg('SomeNamespace\SomeClass', 'someCall', 0, 0, 'query'), | ||
new RenameFunctionLikeParamWithinCallLikeArg( | ||
'SomeNamespace\SomeClassForNamed', | ||
'someCall', | ||
'callback', | ||
0, | ||
'query', | ||
), | ||
]); | ||
|
||
$rectorConfig->phpVersion(PhpVersionFeature::MIXED_TYPE); | ||
}; |
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
Oops, something went wrong.