File tree 2 files changed +37
-26
lines changed
2 files changed +37
-26
lines changed Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace PHPStan \Internal ;
4
+
5
+ use function array_shift ;
6
+
7
+ final class CombinationsHelper
8
+ {
9
+
10
+ /**
11
+ * @param array<mixed> $arrays
12
+ * @return iterable<mixed>
13
+ */
14
+ public static function combinations (array $ arrays ): iterable
15
+ {
16
+ // from https://stackoverflow.com/a/70800936/565782 by Arnaud Le Blanc
17
+ if ($ arrays === []) {
18
+ yield [];
19
+ return ;
20
+ }
21
+
22
+ $ head = array_shift ($ arrays );
23
+
24
+ foreach ($ head as $ elem ) {
25
+ foreach (self ::combinations ($ arrays ) as $ combination ) {
26
+ $ comb = [$ elem ];
27
+ foreach ($ combination as $ c ) {
28
+ $ comb [] = $ c ;
29
+ }
30
+ yield $ comb ;
31
+ }
32
+ }
33
+ }
34
+
35
+ }
Original file line number Diff line number Diff line change 4
4
5
5
use PhpParser \Node \Expr \FuncCall ;
6
6
use PHPStan \Analyser \Scope ;
7
+ use PHPStan \Internal \CombinationsHelper ;
7
8
use PHPStan \Reflection \FunctionReflection ;
8
9
use PHPStan \Reflection \InitializerExprTypeResolver ;
9
10
use PHPStan \Reflection \ParametersAcceptorSelector ;
@@ -94,7 +95,7 @@ public function getTypeFromFunctionCall(
94
95
$ values [] = $ argType ->getConstantScalarValues ();
95
96
}
96
97
97
- $ combinations = $ this -> combinations ($ values );
98
+ $ combinations = CombinationsHelper:: combinations ($ values );
98
99
$ returnTypes = [];
99
100
foreach ($ combinations as $ combination ) {
100
101
$ format = array_shift ($ combination );
@@ -120,29 +121,4 @@ public function getTypeFromFunctionCall(
120
121
return TypeCombinator::union (...$ returnTypes );
121
122
}
122
123
123
- /**
124
- * @param array<mixed> $arrays
125
- * @return iterable<mixed>
126
- */
127
- private function combinations (array $ arrays ): iterable
128
- {
129
- // from https://stackoverflow.com/a/70800936/565782 by Arnaud Le Blanc
130
- if ($ arrays === []) {
131
- yield [];
132
- return ;
133
- }
134
-
135
- $ head = array_shift ($ arrays );
136
-
137
- foreach ($ head as $ elem ) {
138
- foreach ($ this ->combinations ($ arrays ) as $ combination ) {
139
- $ comb = [$ elem ];
140
- foreach ($ combination as $ c ) {
141
- $ comb [] = $ c ;
142
- }
143
- yield $ comb ;
144
- }
145
- }
146
- }
147
-
148
124
}
You can’t perform that action at this time.
0 commit comments