-
-
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.
[Php80] Add AddParamBasedOnParentClassMethodRector (#1431)
* [Php80] Add AddParamBasedOnParentClassMethodRector * use ParentClassMethodTypeOverrideGuard to get parent MethodReflection * add test * [ci-review] Rector Rectify * [ci-review] Rector Rectify * register to php80 config set * phpstan * try compare * skip __construct, it is allowed to have different parameter * [ci-review] Rector Rectify * Fixed * move parent to Source dir * skip construct test * skip no parent method test * skip parent with private method tset * skip same params * skip child more params * eol * eol * do not change same param different name * eol * add failing fixture for skip duplicated previous param * skip duplicated next param next param name * clean up * clean up * final touch: skip used in stmts, eg, in coalesce * add findFirstInFunctionLikeScoped in BetterNodeFinder to look node in scoped * [ci-review] Rector Rectify * [ci-review] Rector Rectify * final touch: check nearest FunctionLike for ClassMethod, Function_ or Closure for parent to check scope * [ci-review] Rector Rectify * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
c26d6cc
commit c445b5a
Showing
21 changed files
with
482 additions
and
1 deletion.
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
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
33 changes: 33 additions & 0 deletions
33
...hod/AddParamBasedOnParentClassMethodRector/AddParamBasedOnParentClassMethodRectorTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class AddParamBasedOnParentClassMethodRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ramBasedOnParentClassMethodRector/Fixture/do_not_change_same_param_different_name.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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\MultiParams; | ||
|
||
class DoNotChangeSameParamDifferentName extends MultiParams{ | ||
public function execute($x) | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\MultiParams; | ||
|
||
class DoNotChangeSameParamDifferentName extends MultiParams{ | ||
public function execute($x, $bar) | ||
{ | ||
} | ||
} | ||
|
||
?> |
27 changes: 27 additions & 0 deletions
27
...s/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/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,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
class B extends ParentWithParam{ | ||
public function execute() | ||
{ | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
class B extends ParentWithParam{ | ||
public function execute($foo) | ||
{ | ||
} | ||
} | ||
|
||
?> |
12 changes: 12 additions & 0 deletions
12
...ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/skip_child_more_params.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,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
// ref https://3v4l.org/op5lE | ||
class SkipChildMoreParams extends ParentWithParam{ | ||
public function execute($foo, $bar) | ||
{ | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/skip_construct.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,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithConstruct; | ||
|
||
class SkipConstruct extends ParentWithConstruct | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...hod/AddParamBasedOnParentClassMethodRector/Fixture/skip_duplicated_previous_param.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,17 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\MultiParams; | ||
|
||
/** | ||
* @bar, $bar will cause error Fatal error: Redefinition of parameter $bar | ||
* | ||
* @see https://3v4l.org/JaX5m | ||
*/ | ||
class SkipDuplicatedPreviousParam extends MultiParams{ | ||
public function execute($bar) | ||
{ | ||
echo $bar; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/skip_no_parent_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,10 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
class SkipNoParentMethod | ||
{ | ||
public function execute() | ||
{ | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...od/AddParamBasedOnParentClassMethodRector/Fixture/skip_parent_with_private_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,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithPrivateMethod; | ||
|
||
class SkipParentWithPrivateMethod extends ParentWithPrivateMethod | ||
{ | ||
public function execute() | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/skip_same_param.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\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
class SkipSameParam extends ParentWithParam{ | ||
public function execute($foo) | ||
{ | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/skip_used_in_coalesce.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,14 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
class SkipUsedInCoalesce extends ParentWithParam{ | ||
public function execute() | ||
{ | ||
echo $foo ?? 'test'; | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
...or/ClassMethod/AddParamBasedOnParentClassMethodRector/Fixture/used_but_in_closure.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,33 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
class UsedButInClosure extends ParentWithParam{ | ||
public function execute() | ||
{ | ||
$x = function () { | ||
echo $foo ?? 'test'; | ||
}; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Fixture; | ||
|
||
use Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source\ParentWithParam; | ||
|
||
class UsedButInClosure extends ParentWithParam{ | ||
public function execute($foo) | ||
{ | ||
$x = function () { | ||
echo $foo ?? 'test'; | ||
}; | ||
} | ||
} | ||
|
||
?> |
10 changes: 10 additions & 0 deletions
10
...ts/Php80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/Source/MultiParams.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 | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source; | ||
|
||
class MultiParams | ||
{ | ||
public function execute($foo, $bar) | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
.../Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/Source/ParentWithConstruct.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 | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source; | ||
|
||
class ParentWithConstruct | ||
{ | ||
public function __construct($foo) | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...hp80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/Source/ParentWithParam.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 | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source; | ||
|
||
class ParentWithParam | ||
{ | ||
public function execute($foo) | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...tor/ClassMethod/AddParamBasedOnParentClassMethodRector/Source/ParentWithPrivateMethod.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 | ||
|
||
namespace Rector\Tests\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector\Source; | ||
|
||
class ParentWithPrivateMethod | ||
{ | ||
private function execute($foo) | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...hp80/Rector/ClassMethod/AddParamBasedOnParentClassMethodRector/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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(AddParamBasedOnParentClassMethodRector::class); | ||
}; |
Oops, something went wrong.