66use PHPStan \Analyser \Scope ;
77use PHPStan \Reflection \Php \PhpMethodFromParserNodeReflection ;
88use PHPStan \Rules \Rule ;
9+ use PHPStan \ShouldNotHappenException ;
910use PHPUnit \Framework \TestCase ;
1011use function count ;
1112
@@ -30,12 +31,29 @@ public function __construct(
3031
3132 public function getNodeType (): string
3233 {
33- return Node \ Stmt \Return_ ::class;
34+ return Node::class;
3435 }
3536
3637 public function processNode (Node $ node , Scope $ scope ): array
3738 {
38- if (!$ node ->expr instanceof Node \Expr \Array_) {
39+ if ($ node instanceof Node \Stmt \Return_) {
40+ if (!$ node ->expr instanceof Node \Expr \Array_) {
41+ return [];
42+ }
43+
44+ $ arrayExprs = [];
45+ foreach ($ node ->expr ->items as $ item ) {
46+ if (!$ item ->value instanceof Node \Expr \Array_) {
47+ return [];
48+ }
49+ $ arrayExprs [] = $ item ->value ;
50+ }
51+ } elseif ($ node instanceof Node \Expr \Yield_) {
52+ if (!$ node ->value instanceof Node \Expr \Array_) {
53+ return [];
54+ }
55+ $ arrayExprs = [$ node ->value ];
56+ } else {
3957 return [];
4058 }
4159
@@ -77,12 +95,12 @@ public function processNode(Node $node, Scope $scope): array
7795 return [];
7896 }
7997
80- foreach ($ node -> expr -> items as $ item ) {
81- if (!$ item -> value instanceof Node \Expr \Array_) {
82- continue ;
98+ foreach ($ arrayExprs as $ arrayExpr ) {
99+ if (!$ arrayExpr instanceof Node \Expr \Array_) {
100+ throw new ShouldNotHappenException () ;
83101 }
84102
85- $ args = $ this ->arrayItemsToArgs ($ item -> value );
103+ $ args = $ this ->arrayItemsToArgs ($ arrayExpr );
86104 if ($ args === null ) {
87105 continue ;
88106 }
@@ -92,7 +110,7 @@ public function processNode(Node $node, Scope $scope): array
92110 $ var ,
93111 $ testsWithProvider [0 ]->getName (),
94112 $ args ,
95- ['startLine ' => $ item ->getStartLine ()],
113+ ['startLine ' => $ arrayExpr ->getStartLine ()],
96114 ));
97115 }
98116
0 commit comments