File tree Expand file tree Collapse file tree
rules-tests/CodeQuality/Rector/CallLike/DirectInstanceOverMockArgRector/Fixture
rules/CodeQuality/Rector/CallLike 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 \CallLike \DirectInstanceOverMockArgRector \Fixture ;
4+
5+ final class SkipNonTestClassSpreadNamedArg
6+ {
7+ public function run ($ request )
8+ {
9+ return new SomeData (
10+ ...$ request ->updateData (),
11+ user: (string ) $ request ->user ()->getKey (),
12+ );
13+ }
14+ }
Original file line number Diff line number Diff line change 1313use PhpParser \Node \Expr \StaticCall ;
1414use PhpParser \Node \Name \FullyQualified ;
1515use Rector \PhpParser \Node \Value \ValueResolver ;
16- use Rector \PHPStan \ScopeFetcher ;
17- use Rector \PHPUnit \Enum \PHPUnitClassName ;
16+ use Rector \PHPUnit \NodeAnalyzer \TestsNodeAnalyzer ;
1817use Rector \Rector \AbstractRector ;
1918use Rector \Symfony \Enum \SymfonyClass ;
2019use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
2625final class DirectInstanceOverMockArgRector extends AbstractRector
2726{
2827 public function __construct (
29- private readonly ValueResolver $ valueResolver
28+ private readonly ValueResolver $ valueResolver ,
29+ private readonly TestsNodeAnalyzer $ testsNodeAnalyzer
3030 ) {
3131 }
3232
@@ -88,13 +88,8 @@ public function getNodeTypes(): array
8888 */
8989 public function refactor (Node $ node ): MethodCall |StaticCall |New_ |ArrayItem |null
9090 {
91- $ scope = ScopeFetcher ::fetch ($ node );
92- if (! $ scope ->isInClass ()) {
93- return null ;
94- }
95-
96- $ classReflection = $ scope ->getClassReflection ();
97- if (! $ classReflection ->is (PHPUnitClassName::TEST_CASE )) {
91+ // run on test classes only, non-test code may lack scope on args and crash the whole run
92+ if (! $ this ->testsNodeAnalyzer ->isInTestClass ($ node )) {
9893 return null ;
9994 }
10095
You can’t perform that action at this time.
0 commit comments