Conditions | 4 |
Paths | 3 |
Total Lines | 17 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
56 | 6 | protected function get(array $dataset, $length) |
|
57 | { |
||
58 | 6 | $originalLength = count($dataset); |
|
59 | 6 | $remainingLength = $originalLength - $length + 1; |
|
60 | 6 | for ($i = 0; $i < $remainingLength; $i++) { |
|
61 | 6 | $current = $dataset[$i]; |
|
62 | 6 | if ($length === 1) { |
|
63 | 6 | yield [$current]; |
|
64 | 6 | } else { |
|
65 | 6 | $remaining = array_slice($dataset, $i + 1); |
|
66 | 6 | foreach ($this->get($remaining, $length - 1) as $permutation) { |
|
67 | 6 | array_unshift($permutation, $current); |
|
68 | 6 | yield $permutation; |
|
69 | 6 | } |
|
70 | } |
||
71 | 6 | } |
|
72 | 6 | } |
|
73 | } |
||
74 |