File tree Expand file tree Collapse file tree 3 files changed +77
-2
lines changed
rules-tests/CodeQuality/Rector/ClassMethod/RemoveStandaloneCreateMockRector/Fixture
rules/CodeQuality/Rector/ClassMethod Expand file tree Collapse file tree 3 files changed +77
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \ClassMethod \RemoveStandaloneCreateMockRector \Fixture ;
6+
7+ final class HandleMultiples extends \PHPUnit \Framework \TestCase
8+ {
9+ public function testSomething (): void
10+ {
11+ $ this ->createMock ('someClass ' );
12+ $ this ->createMock ('someClass ' );
13+ $ this ->createMock ('someClass ' );
14+ $ this ->createMock ('someClass ' );
15+ }
16+ }
17+
18+ ?>
19+ -----
20+ <?php
21+
22+ declare (strict_types=1 );
23+
24+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \ClassMethod \RemoveStandaloneCreateMockRector \Fixture ;
25+
26+ final class HandleMultiples extends \PHPUnit \Framework \TestCase
27+ {
28+ public function testSomething (): void
29+ {
30+ }
31+ }
32+
33+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \ClassMethod \RemoveStandaloneCreateMockRector \Fixture ;
6+
7+ final class HandleNestedCall extends \PHPUnit \Framework \TestCase
8+ {
9+ public function testSomething (): void
10+ {
11+ $ this ->createMock ('someClass ' )
12+ ->method ('some ' )
13+ ->willReturn (100 );
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ declare (strict_types=1 );
22+
23+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \ClassMethod \RemoveStandaloneCreateMockRector \Fixture ;
24+
25+ final class HandleNestedCall extends \PHPUnit \Framework \TestCase
26+ {
27+ public function testSomething (): void
28+ {
29+ }
30+ }
31+
32+ ?>
Original file line number Diff line number Diff line change @@ -84,8 +84,8 @@ public function refactor(Node $node): ?Node
8484 continue ;
8585 }
8686
87- $ methodCall = $ stmt ->expr ;
88- if (! $ this ->isName ($ methodCall ->name , 'createMock ' )) {
87+ $ topmostCall = $ this -> resolveTopmostCall ( $ stmt ->expr ) ;
88+ if (! $ this ->isName ($ topmostCall ->name , 'createMock ' )) {
8989 continue ;
9090 }
9191
@@ -99,4 +99,14 @@ public function refactor(Node $node): ?Node
9999
100100 return null ;
101101 }
102+
103+ private function resolveTopmostCall (MethodCall $ methodCall ): MethodCall
104+ {
105+ $ currentMethodCall = $ methodCall ;
106+ while ($ currentMethodCall ->var instanceof MethodCall) {
107+ $ currentMethodCall = $ currentMethodCall ->var ;
108+ }
109+
110+ return $ currentMethodCall ;
111+ }
102112}
You can’t perform that action at this time.
0 commit comments