@@ -47,34 +47,15 @@ public function processNode(Node $node, Scope $scope): array
4747 return [];
4848 }
4949
50- $ arraysTypes = [];
51- if ($ node instanceof Node \Stmt \Return_ || $ node instanceof Node \Expr \YieldFrom) {
52- if ($ node ->expr === null ) {
53- return [];
54- }
55-
56- $ exprType = $ scope ->getType ($ node ->expr );
57- $ exprConstArrays = $ exprType ->getConstantArrays ();
58- foreach ($ exprConstArrays as $ constArray ) {
59- foreach ($ constArray ->getValueTypes () as $ valueType ) {
60- foreach ($ valueType ->getConstantArrays () as $ constValueArray ) {
61- $ arraysTypes [] = $ constValueArray ;
62- }
63- }
64- }
65-
66- if ($ arraysTypes === []) {
67- $ arraysTypes = $ exprType ->getIterableValueType ()->getArrays ();
68- }
69- } elseif ($ node instanceof Node \Expr \Yield_) {
70- if ($ node ->value === null ) {
71- return [];
72- }
73-
74- $ exprType = $ scope ->getType ($ node ->value );
75- $ arraysTypes = $ exprType ->getConstantArrays ();
50+ if (
51+ !$ node instanceof Node \Stmt \Return_
52+ && !$ node instanceof Node \Expr \Yield_
53+ && !$ node instanceof Node \Expr \YieldFrom
54+ ) {
55+ return [];
7656 }
7757
58+ $ arraysTypes = $ this ->buildArrayTypesFromNode ($ node , $ scope );
7859 if ($ arraysTypes === []) {
7960 return [];
8061 }
@@ -182,4 +163,41 @@ private function arrayItemsToArgs(Type $array, int $numberOfParameters): ?array
182163 return $ args ;
183164 }
184165
166+ /**
167+ * @param Node\Stmt\Return_|Node\Expr\Yield_|Node\Expr\YieldFrom $node
168+ * @return array<Type>
169+ */
170+ private function buildArrayTypesFromNode (Node $ node , Scope $ scope ): array
171+ {
172+ $ arraysTypes = [];
173+ if ($ node instanceof Node \Stmt \Return_ || $ node instanceof Node \Expr \YieldFrom) {
174+ if ($ node ->expr === null ) {
175+ return [];
176+ }
177+
178+ $ exprType = $ scope ->getType ($ node ->expr );
179+ $ exprConstArrays = $ exprType ->getConstantArrays ();
180+ foreach ($ exprConstArrays as $ constArray ) {
181+ foreach ($ constArray ->getValueTypes () as $ valueType ) {
182+ foreach ($ valueType ->getConstantArrays () as $ constValueArray ) {
183+ $ arraysTypes [] = $ constValueArray ;
184+ }
185+ }
186+ }
187+
188+ if ($ arraysTypes === []) {
189+ $ arraysTypes = $ exprType ->getIterableValueType ()->getArrays ();
190+ }
191+ } elseif ($ node instanceof Node \Expr \Yield_) {
192+ if ($ node ->value === null ) {
193+ return [];
194+ }
195+
196+ $ exprType = $ scope ->getType ($ node ->value );
197+ $ arraysTypes = $ exprType ->getConstantArrays ();
198+ }
199+
200+ return $ arraysTypes ;
201+ }
202+
185203}
0 commit comments