File tree Expand file tree Collapse file tree
rules-tests/TypeDeclarationDocblocks/Rector/ClassMethod/DocblockReturnArrayFromDirectArrayInstanceRector/Fixture
rules/TypeDeclarationDocblocks/Rector/ClassMethod Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \DocblockReturnArrayFromDirectArrayInstanceRector \Fixture ;
4+
5+ final class IncludeMissingReturnArray
6+ {
7+ public function getNames ()
8+ {
9+ return [
10+ 'key ' => 'value ' ,
11+ ];
12+ }
13+ }
14+
15+ ?>
16+ -----
17+ <?php
18+
19+ namespace Rector \Tests \TypeDeclarationDocblocks \Rector \ClassMethod \DocblockReturnArrayFromDirectArrayInstanceRector \Fixture ;
20+
21+ final class IncludeMissingReturnArray
22+ {
23+ /**
24+ * @return array<string, string>
25+ */
26+ public function getNames ()
27+ {
28+ return [
29+ 'key ' => 'value ' ,
30+ ];
31+ }
32+ }
33+
34+ ?>
Original file line number Diff line number Diff line change @@ -43,7 +43,9 @@ public function getNodeTypes(): array
4343
4444 public function getRuleDefinition (): RuleDefinition
4545 {
46- return new RuleDefinition ('Add @return array docblock based on direct single level direct return of [] ' , [
46+ return new RuleDefinition (
47+ 'Add simple @return array docblock based on direct single level direct return of [] ' ,
48+ [
4749 new CodeSample (
4850 <<<'CODE_SAMPLE'
4951class SomeClass
@@ -72,6 +74,7 @@ public function getItems(): array
7274}
7375CODE_SAMPLE
7476 ),
77+
7578 ]);
7679 }
7780
@@ -80,22 +83,14 @@ public function getItems(): array
8083 */
8184 public function refactor (Node $ node ): ?Node
8285 {
83- if (! $ node ->returnType instanceof Node) {
84- return null ;
85- }
86-
87- if (! $ this ->isName ($ node ->returnType , 'array ' )) {
88- return null ;
89- }
90-
9186 $ phpDocInfo = $ this ->phpDocInfoFactory ->createFromNodeOrEmpty ($ node );
9287
9388 // return tag is already given
9489 if ($ phpDocInfo ->getReturnTagValue () instanceof ReturnTagValueNode) {
9590 return null ;
9691 }
9792
98- if (count ($ node ->stmts ) !== 1 ) {
93+ if ($ node -> stmts === null || count ($ node ->stmts ) !== 1 ) {
9994 return null ;
10095 }
10196
You can’t perform that action at this time.
0 commit comments