Completed
Push — master ( f42091...b2313d )
by Pol
02:14
created

Permutations::generator()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 4
nop 1
crap 4
1
<?php
2
3
namespace drupol\phpermutations\Generators;
4
5
/**
6
 * Class Permutations.
7
 *
8
 * @package drupol\phpermutations\Generators
9
 */
10
class Permutations {
11
12
  /**
13
   * @param $data
14
   *
15
   * @return \Generator
16
   */
17 1
  public function generator($data) {
18 1
    if (count($data) <= 1) {
19 1
      yield $data;
20 1
    } else {
21 1
      foreach (range(0, count($data) - 1) as $i) {
22 1
        foreach ($this->generator(array_slice($data, 1)) as $item) {
23 1
          yield array_merge(array_slice($item, 0, $i), array_slice($data, 0, 1), array_slice($item, $i));
24 1
        }
25 1
      }
26
    }
27 1
  }
28
29
}
30
31