File tree Expand file tree Collapse file tree 2 files changed +37
-26
lines changed
Expand file tree Collapse file tree 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 44
55use PhpParser \Node \Expr \FuncCall ;
66use PHPStan \Analyser \Scope ;
7+ use PHPStan \Internal \CombinationsHelper ;
78use PHPStan \Reflection \FunctionReflection ;
89use PHPStan \Reflection \InitializerExprTypeResolver ;
910use PHPStan \Reflection \ParametersAcceptorSelector ;
@@ -94,7 +95,7 @@ public function getTypeFromFunctionCall(
9495 $ values [] = $ argType ->getConstantScalarValues ();
9596 }
9697
97- $ combinations = $ this -> combinations ($ values );
98+ $ combinations = CombinationsHelper:: combinations ($ values );
9899 $ returnTypes = [];
99100 foreach ($ combinations as $ combination ) {
100101 $ format = array_shift ($ combination );
@@ -120,29 +121,4 @@ public function getTypeFromFunctionCall(
120121 return TypeCombinator::union (...$ returnTypes );
121122 }
122123
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-
148124}
You can’t perform that action at this time.
0 commit comments