File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed
rules-tests/Unambiguous/Rector/Expression/FluentSettersToStandaloneCallMethodRector
rules/Unambiguous/Rector/Expression Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Unambiguous \Rector \Expression \FluentSettersToStandaloneCallMethodRector \Fixture ;
4+
5+ use Rector \Tests \Unambiguous \Rector \Expression \FluentSettersToStandaloneCallMethodRector \Source \SetNameCaller ;
6+
7+ class SkipReturnDifferentObject
8+ {
9+ public function setup ()
10+ {
11+ return (new SetNameCaller ())
12+ ->setName ('John ' )
13+ ->setSurname ('Doe ' );
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Unambiguous \Rector \Expression \FluentSettersToStandaloneCallMethodRector \Source ;
4+
5+ class SetNameCaller
6+ {
7+ public function setName (): SurnameCaller
8+ {
9+ return new SurnameCaller ();
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \Unambiguous \Rector \Expression \FluentSettersToStandaloneCallMethodRector \Source ;
4+
5+ class SurnameCaller
6+ {
7+ public function setSurname (): self
8+ {
9+ return $ this ;
10+ }
11+ }
Original file line number Diff line number Diff line change @@ -98,12 +98,28 @@ public function refactor(Node $node): ?array
9898 $ methodCalls = [];
9999
100100 $ currentMethodCall = $ firstMethodCall ;
101+ $ classNameObjectType = null ;
101102 while ($ currentMethodCall instanceof MethodCall) {
103+ if ($ currentMethodCall ->isFirstClassCallable ()) {
104+ return null ;
105+ }
106+
102107 // must be exactly one argument
103108 if (count ($ currentMethodCall ->getArgs ()) !== 1 ) {
104109 return null ;
105110 }
106111
112+ $ objectType = $ this ->getType ($ currentMethodCall ->var );
113+ if (! $ objectType instanceof ObjectType) {
114+ return null ;
115+ }
116+
117+ if ($ classNameObjectType === null ) {
118+ $ classNameObjectType = $ objectType ->getClassName ();
119+ } elseif ($ classNameObjectType !== $ objectType ->getClassName ()) {
120+ return null ;
121+ }
122+
107123 $ methodCalls [] = $ currentMethodCall ;
108124 $ currentMethodCall = $ currentMethodCall ->var ;
109125 }
You can’t perform that action at this time.
0 commit comments