55namespace Rector \Tests \BetterPhpDocParser \PhpDoc \ArrayItemNode ;
66
77use Nette \Utils \FileSystem as UtilsFileSystem ;
8- use PhpParser \Node ;
8+ use PhpParser \Node \Stmt \Class_ ;
9+ use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfo ;
910use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1011use Rector \BetterPhpDocParser \Printer \PhpDocInfoPrinter ;
1112use Rector \Comments \NodeDocBlock \DocBlockUpdater ;
13+ use Rector \Contract \PhpParser \Node \StmtsAwareInterface ;
1214use Rector \NodeTypeResolver \NodeScopeAndMetadataDecorator ;
1315use Rector \PhpParser \Parser \RectorParser ;
1416use Rector \Testing \PHPUnit \AbstractLazyTestCase ;
15- use Rector \ValueObject \Application \File ;
1617
17- class ArrayItemNodeTest extends AbstractLazyTestCase
18+ final class ArrayItemNodeTest extends AbstractLazyTestCase
1819{
1920 private DocBlockUpdater $ docBlockUpdater ;
2021
@@ -39,7 +40,6 @@ public function testUpdateNestedClassAnnotation(): void
3940 {
4041 $ filePath = __DIR__ . '/FixtureNested/DoctrineNestedClassAnnotation.php.inc ' ;
4142 $ fileContent = UtilsFileSystem::read ($ filePath );
42- $ file = new File ($ filePath , $ fileContent );
4343
4444 $ stmtsAndTokens = $ this ->rectorParser ->parseFileContentToStmtsAndTokens ($ fileContent );
4545 $ oldStmts = $ stmtsAndTokens ->getStmts ();
@@ -48,17 +48,25 @@ public function testUpdateNestedClassAnnotation(): void
4848 $ classStmt = null ;
4949 $ classDocComment = null ;
5050
51- foreach ($ newStmts as $ node ) {
52- if ($ node -> stmts === null ) {
51+ foreach ($ newStmts as $ newStmt ) {
52+ if (! $ newStmt instanceof StmtsAwareInterface ) {
5353 continue ;
5454 }
5555
56- foreach ($ node ->stmts as $ stmt ) {
57- if (! $ stmt instanceof Node \Stmt \Class_) {
56+ if ($ newStmt ->stmts === null ) {
57+ continue ;
58+ }
59+
60+ foreach ($ newStmt ->stmts as $ stmt ) {
61+ if (! $ stmt instanceof Class_) {
5862 continue ;
5963 }
6064
6165 $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNode ($ stmt );
66+ if (! $ phpDocInfo instanceof PhpDocInfo) {
67+ continue ;
68+ }
69+
6270 $ phpDocNode = $ phpDocInfo ->getPhpDocNode ();
6371
6472 foreach ($ phpDocNode ->children as $ key => $ phpDocChildNode ) {
@@ -70,21 +78,25 @@ public function testUpdateNestedClassAnnotation(): void
7078 break ;
7179 }
7280
81+ if (! $ classStmt instanceof Class_) {
82+ continue ;
83+ }
84+
7385 $ this ->docBlockUpdater ->updateRefactoredNodeWithPhpDocInfo ($ classStmt );
7486 $ classDocComment = $ this ->printNodePhpDocInfoToString ($ classStmt );
7587 }
7688
7789 $ this ->assertEquals (
78- '/**
90+ str_replace ( "\r\n" , "\n" , '/**
7991 * @ORM\Table(name="doctrine_entity", uniqueConstraints={@ORM\UniqueConstraint(name="property")})
80- */ ' ,
81- $ classDocComment
92+ */ ') ,
93+ str_replace ( "\r\n" , "\n" , ( string ) $ classDocComment)
8294 );
8395 }
8496
85- private function printNodePhpDocInfoToString (Node $ node ): string
97+ private function printNodePhpDocInfoToString (Class_ $ class ): string
8698 {
87- $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ node );
99+ $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ class );
88100 return $ this ->phpDocInfoPrinter ->printFormatPreserving ($ phpDocInfo );
89101 }
90102}
0 commit comments