File tree Expand file tree Collapse file tree
rules-tests/CodeQuality/Rector/MethodCall/NarrowIdenticalWithConsecutiveRector/Fixture
rules/CodeQuality/Rector/MethodCall Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \NarrowIdenticalWithConsecutiveRector \Fixture ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use Rector \PHPUnit \Tests \CodeQuality \Rector \MethodCall \NarrowIdenticalWithConsecutiveRector \Source \SomeMockedClass ;
7+
8+ final class SkipNewObject extends TestCase
9+ {
10+ public function test ()
11+ {
12+ $ someServiceMock = $ this ->createMock (SomeMockedClass::class);
13+ $ someServiceMock ->expects ($ this ->exactly (3 ))
14+ ->method ('prepare ' )
15+ ->withConsecutive (
16+ [new \stdClass ()],
17+ [new \stdClass ()],
18+ [new \stdClass ()],
19+ );
20+ }
21+ }
Original file line number Diff line number Diff line change 77use PhpParser \Node ;
88use PhpParser \Node \Arg ;
99use PhpParser \Node \Expr \MethodCall ;
10+ use PhpParser \Node \Expr \New_ ;
1011use PhpParser \Node \Identifier ;
1112use PhpParser \PrettyPrinter \Standard ;
13+ use Rector \PhpParser \Node \BetterNodeFinder ;
1214use Rector \PHPUnit \NodeAnalyzer \TestsNodeAnalyzer ;
1315use Rector \Rector \AbstractRector ;
1416use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
2022final class NarrowIdenticalWithConsecutiveRector extends AbstractRector
2123{
2224 public function __construct (
23- private readonly TestsNodeAnalyzer $ testsNodeAnalyzer
25+ private readonly TestsNodeAnalyzer $ testsNodeAnalyzer ,
26+ private readonly BetterNodeFinder $ betterNodeFinder
2427 ) {
2528 }
2629
@@ -104,6 +107,11 @@ public function refactor(Node $node): MethodCall|null
104107 return null ;
105108 }
106109
110+ // skip new object instances, as each creates a fresh instance with possible property dependency
111+ if ($ this ->betterNodeFinder ->hasInstancesOf ($ node ->getArgs (), [New_::class])) {
112+ return null ;
113+ }
114+
107115 $ uniqueArgValues = $ this ->resolveUniqueArgValues ($ node );
108116
109117 // multiple unique values
You can’t perform that action at this time.
0 commit comments