File tree Expand file tree Collapse file tree 3 files changed +48
-5
lines changed
tests/BetterPhpDocParser/PhpDoc/ArrayItemNode Expand file tree Collapse file tree 3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change 3535 __DIR__ . '/config ' ,
3636 __DIR__ . '/build/build-preload.php ' ,
3737 ])
38+ ->withRules ([
39+ \Rector \Utils \Rector \MakeUseOfContaintsStmtsRector::class,
40+ ])
3841 ->withRootFiles ()
3942 ->withImportNames (removeUnusedImports: true )
4043 ->withSkip ([
Original file line number Diff line number Diff line change @@ -55,11 +55,7 @@ public function testUpdateNestedClassAnnotation(): void
5555 continue ;
5656 }
5757
58- if ($ newStmt ->stmts === null ) {
59- continue ;
60- }
61-
62- foreach ($ newStmt ->stmts as $ stmt ) {
58+ foreach ($ newStmt ->getStmts () as $ stmt ) {
6359 if (! $ stmt instanceof Class_) {
6460 continue ;
6561 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Utils \Rector ;
6+
7+ // e.g. to move PhpDocInfo to the particular rule itself
8+ use PhpParser \Node ;
9+ use PhpParser \Node \ContainsStmts ;
10+ use PhpParser \Node \Expr \MethodCall ;
11+ use PhpParser \Node \Expr \PropertyFetch ;
12+ use PHPStan \Type \ObjectType ;
13+ use Rector \Rector \AbstractRector ;
14+ use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
15+
16+ final class MakeUseOfContaintsStmtsRector extends AbstractRector
17+ {
18+ public function getRuleDefinition (): RuleDefinition
19+ {
20+ // @see https://github.com/nikic/PHP-Parser/pull/1113
21+ return new RuleDefinition ('Move $node->stmts to $node->getStmts() for ContaintsStmts ' , []);
22+ }
23+
24+ public function getNodeTypes (): array
25+ {
26+ return [PropertyFetch::class];
27+ }
28+
29+ /**
30+ * @param PropertyFetch $node
31+ */
32+ public function refactor (Node $ node ): ?Node
33+ {
34+ if (! $ this ->isName ($ node ->name , 'stmts ' )) {
35+ return null ;
36+ }
37+
38+ if (! $ this ->isObjectType ($ node ->var , new ObjectType (ContainsStmts::class))) {
39+ return null ;
40+ }
41+
42+ return new MethodCall ($ node ->var , 'getStmts ' );
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments