| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | final class Combinations |
||
| 8 | { |
||
| 9 | 6 | public function getAllCombinations(array $arguments, array $currentCombination = []): array |
|
| 10 | { |
||
| 11 | 6 | $combinations = []; |
|
| 12 | 6 | $argumentsTail = $arguments; |
|
| 13 | 6 | $key = key($argumentsTail); |
|
| 14 | 6 | unset($argumentsTail[$key]); |
|
| 15 | |||
| 16 | 6 | if (0 === count($arguments)) { |
|
| 17 | 6 | return [$currentCombination]; |
|
| 18 | } |
||
| 19 | |||
| 20 | 6 | foreach (current($arguments) as $element) { |
|
| 21 | 6 | $newCombination = $currentCombination; |
|
| 22 | 6 | array_push($newCombination, $element); |
|
| 23 | 6 | $combinations = $this->extend( |
|
| 24 | 6 | $this->getAllCombinations($argumentsTail, $newCombination), |
|
| 25 | $combinations |
||
| 26 | ); |
||
| 27 | } |
||
| 28 | |||
| 29 | 6 | return $combinations; |
|
| 30 | } |
||
| 31 | |||
| 32 | 6 | private function extend(array $first, array $second): array |
|
| 39 | } |
||
| 40 | } |
||
| 41 |