File tree Expand file tree Collapse file tree 3 files changed +66
-8
lines changed
rules-tests/CodeQuality/Rector/Class_/InlineStubPropertyToCreateStubMethodCallRector/Fixture Expand file tree Collapse file tree 3 files changed +66
-8
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \InlineStubPropertyToCreateStubMethodCallRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use PHPUnit \Framework \MockObject \Stub ;
7+ use Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \InlineStubPropertyToCreateStubMethodCallRector \Source \NotRelevantClass ;
8+
9+ final class InlineUsedInCalls extends TestCase
10+ {
11+ private Stub $ someStub ;
12+
13+ protected function setUp (): void
14+ {
15+ $ this ->someStub = $ this ->createStub (NotRelevantClass::class);
16+ }
17+
18+ public function testAnother ()
19+ {
20+ $ anotherObject = new NotRelevantClass ($ this ->someStub );
21+
22+ $ this ->runThis ($ this ->someStub );
23+ }
24+
25+ private function runThis ($ object )
26+ {
27+ }
28+ }
29+
30+ ?>
31+ -----
32+ <?php
33+
34+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \InlineStubPropertyToCreateStubMethodCallRector \Fixture ;
35+
36+ use PHPUnit \Framework \TestCase ;
37+ use PHPUnit \Framework \MockObject \Stub ;
38+ use Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \InlineStubPropertyToCreateStubMethodCallRector \Source \NotRelevantClass ;
39+
40+ final class InlineUsedInCalls extends TestCase
41+ {
42+ protected function setUp (): void
43+ {
44+ }
45+
46+ public function testAnother ()
47+ {
48+ $ anotherObject = new NotRelevantClass ($ this ->createStub (\Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \InlineStubPropertyToCreateStubMethodCallRector \Source \NotRelevantClass::class));
49+
50+ $ this ->runThis ($ this ->createStub (\Rector \PHPUnit \Tests \CodeQuality \Rector \Class_ \InlineStubPropertyToCreateStubMethodCallRector \Source \NotRelevantClass::class));
51+ }
52+
53+ private function runThis ($ object )
54+ {
55+ }
56+ }
57+
58+ ?>
Original file line number Diff line number Diff line change 44
55namespace Rector \PHPUnit \CodeQuality \NodeFinder ;
66
7- use PhpParser \Node \Expr \New_ ;
7+ use PhpParser \Node \Expr \CallLike ;
88use PhpParser \Node \Expr \PropertyFetch ;
99use PhpParser \Node \Stmt \Class_ ;
1010use Rector \NodeNameResolver \NodeNameResolver ;
@@ -21,19 +21,19 @@ public function __construct(
2121 /**
2222 * @return PropertyFetch[]
2323 */
24- public function findInNew (Class_ $ class , string $ propertyName ): array
24+ public function findInCallLikes (Class_ $ class , string $ propertyName ): array
2525 {
26- /** @var New_ [] $news */
27- $ news = $ this ->betterNodeFinder ->findInstancesOfScoped ($ class ->getMethods (), New_ ::class);
26+ /** @var CallLike [] $callLikes */
27+ $ callLikes = $ this ->betterNodeFinder ->findInstancesOfScoped ($ class ->getMethods (), CallLike ::class);
2828
2929 $ propertyFetchesInNewArgs = [];
3030
31- foreach ($ news as $ new ) {
32- if ($ new ->isFirstClassCallable ()) {
31+ foreach ($ callLikes as $ callLike ) {
32+ if ($ callLike ->isFirstClassCallable ()) {
3333 continue ;
3434 }
3535
36- foreach ($ new ->getArgs () as $ arg ) {
36+ foreach ($ callLike ->getArgs () as $ arg ) {
3737 if (! $ arg ->value instanceof PropertyFetch) {
3838 continue ;
3939 }
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ public function refactor(Node $node): ?Node
128128 continue ;
129129 }
130130
131- $ currentPropertyFetchesInNewArgs = $ this ->propertyFetchUsageFinder ->findInNew ($ node , $ propertyName );
131+ $ currentPropertyFetchesInNewArgs = $ this ->propertyFetchUsageFinder ->findInCallLikes ($ node , $ propertyName );
132132
133133 // are there more uses than simple passing to a new instance?
134134 $ totalPropertyFetches = $ this ->propertyFetchFinder ->findLocalPropertyFetchesByName ($ node , $ propertyName );
You can’t perform that action at this time.
0 commit comments