Conditions | 4 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
36 | 2 | protected function get(array $dataset, $length) { |
|
37 | 2 | $originalLength = count($dataset); |
|
38 | 2 | $remainingLength = $originalLength - $length + 1; |
|
39 | 2 | for ($i = 0; $i < $remainingLength; $i++) { |
|
40 | 2 | $current = $dataset[$i]; |
|
41 | 2 | if ($length === 1) { |
|
42 | 2 | yield [$current]; |
|
43 | 2 | } else { |
|
44 | 2 | $remaining = array_slice($dataset, $i + 1); |
|
45 | 2 | foreach ($this->get($remaining, $length - 1) as $permutation) { |
|
46 | 2 | array_unshift($permutation, $current); |
|
47 | 2 | yield $permutation; |
|
48 | 2 | } |
|
49 | } |
||
50 | 2 | } |
|
51 | 2 | } |
|
52 | |||
70 |