File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
rules-tests/TypeDeclaration/Rector/ClassMethod/AddParamFromDimFetchKeyUseRector/Fixture
rules/TypeDeclaration/Rector/ClassMethod Expand file tree Collapse file tree 2 files changed +28
-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+ final class SkipPossiblyNull
6+ {
7+ public function process ($ key )
8+ {
9+ if ($ key === null ) {
10+ return ;
11+ }
12+
13+ $ items = [
14+ 'first ' => 'Firstitem ' ,
15+ 111 => 'Seconditem ' ,
16+ 'second ' => 'Seconditem ' ,
17+ ];
18+
19+ return $ items [$ key ];
20+ }
21+ }
Original file line number Diff line number Diff line change 1313use Rector \PHPStanStaticTypeMapper \Enum \TypeKind ;
1414use Rector \Rector \AbstractRector ;
1515use Rector \StaticTypeMapper \StaticTypeMapper ;
16+ use Rector \TypeDeclaration \Guard \ParamTypeAddGuard ;
1617use Rector \TypeDeclarationDocblocks \NodeFinder \ArrayDimFetchFinder ;
1718use Rector \VendorLocker \ParentClassMethodTypeOverrideGuard ;
1819use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -26,7 +27,8 @@ final class AddParamFromDimFetchKeyUseRector extends AbstractRector
2627 public function __construct (
2728 private readonly ArrayDimFetchFinder $ arrayDimFetchFinder ,
2829 private readonly StaticTypeMapper $ staticTypeMapper ,
29- private readonly ParentClassMethodTypeOverrideGuard $ parentClassMethodTypeOverrideGuard
30+ private readonly ParentClassMethodTypeOverrideGuard $ parentClassMethodTypeOverrideGuard ,
31+ private readonly ParamTypeAddGuard $ paramTypeAddGuard
3032 ) {
3133 }
3234
@@ -107,6 +109,10 @@ public function refactor(Node $node): ?Node
107109 continue ;
108110 }
109111
112+ if (! $ this ->paramTypeAddGuard ->isLegal ($ param , $ classMethod )) {
113+ continue ;
114+ }
115+
110116 foreach ($ dimFetches as $ dimFetch ) {
111117 $ dimFetchType = $ this ->getType ($ dimFetch ->var );
112118
You can’t perform that action at this time.
0 commit comments