File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector
rules/TypeDeclaration/Rector/ClassMethod Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \AddParamFromDimFetchKeyUseRector \Fixture ;
4+
5+ use Rector \Tests \TypeDeclaration \Rector \ClassMethod \AddParamFromDimFetchKeyUseRector \Source \SomeParentMethod ;
6+
7+ final class SkipHasParentMethod extends SomeParentMethod
8+ {
9+ public function process ($ key )
10+ {
11+ $ items = [
12+ 'first ' => 'Firstitem ' ,
13+ 'second ' => 'Seconditem ' ,
14+ ];
15+
16+ return $ items [$ key ];
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \TypeDeclaration \Rector \ClassMethod \AddParamFromDimFetchKeyUseRector \Source ;
6+
7+ class SomeParentMethod
8+ {
9+ public function process ($ key )
10+ {
11+ }
12+ }
Original file line number Diff line number Diff line change 1212use Rector \Rector \AbstractRector ;
1313use Rector \StaticTypeMapper \StaticTypeMapper ;
1414use Rector \TypeDeclarationDocblocks \NodeFinder \ArrayDimFetchFinder ;
15+ use Rector \VendorLocker \ParentClassMethodTypeOverrideGuard ;
1516use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
1617use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
1718
@@ -22,7 +23,8 @@ final class AddParamFromDimFetchKeyUseRector extends AbstractRector
2223{
2324 public function __construct (
2425 private readonly ArrayDimFetchFinder $ arrayDimFetchFinder ,
25- private readonly StaticTypeMapper $ staticTypeMapper
26+ private readonly StaticTypeMapper $ staticTypeMapper ,
27+ private readonly ParentClassMethodTypeOverrideGuard $ parentClassMethodTypeOverrideGuard
2628 ) {
2729 }
2830
@@ -87,6 +89,10 @@ public function refactor(Node $node): ?Node
8789 continue ;
8890 }
8991
92+ if ($ this ->parentClassMethodTypeOverrideGuard ->hasParentClassMethod ($ classMethod )) {
93+ continue ;
94+ }
95+
9096 foreach ($ classMethod ->getParams () as $ param ) {
9197 if ($ param ->type instanceof Node) {
9298 continue ;
You can’t perform that action at this time.
0 commit comments