Completed
Push — master ( 2ef9a2...e0a631 )
by Pol
02:35
created

Rotation   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 78.95%

Importance

Changes 0
Metric Value
wmc 8
cbo 1
dl 0
loc 74
ccs 15
cts 19
cp 0.7895
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A key() 0 3 1
A current() 0 3 1
A next() 0 4 2
A rewind() 0 3 1
A valid() 0 3 1
A count() 0 3 1
1
<?php
2
3
namespace drupol\phpermutations\Iterators;
4
5
use drupol\phpermutations\Combinatorics;
6
7
/**
8
 * Class Rotation.
9
 *
10
 * @package drupol\phpermutations\Iterators
11
 */
12
class Rotation extends Combinatorics implements \Iterator, \Countable {
13
14
  /**
15
   * The key.
16
   *
17
   * @var int
18
   */
19
  protected $key = 0;
20
21
  /**
22
   * A copy of the original data.
23
   *
24
   * @var mixed[]
25
   */
26
  protected $rotation;
27
28
  /**
29
   * Rotation constructor.
30
   *
31
   * @param array $dataset
32
   *   The dataset.
33
   */
34 4
  public function __construct(array $dataset = array()) {
35 4
    parent::__construct($dataset, NULL);
36 4
    $this->rotation = $this->getDataset();
37 4
  }
38
39
  /**
40
   * {@inheritdoc}
41
   */
42
  public function key() {
43
    return $this->key;
44
  }
45
46
  /**
47
   * {@inheritdoc}
48
   */
49 4
  public function current() {
50 4
    return $this->rotation;
51
  }
52
53
  /**
54
   * Compute the next value of the Iterator.
55
   *
56
   * @param int $offset
57
   *   The offset.
58
   */
59 4
  public function next($offset = 1) {
60 4
    $offset = is_null($offset) ? 1 : $offset % $this->count();
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $offset. This often makes code more readable.
Loading history...
61 4
    $this->rotation = array_merge(array_slice($this->rotation, $offset), array_slice($this->rotation, 0, $offset));
62 4
  }
63
64
  /**
65
   * {@inheritdoc}
66
   */
67 4
  public function rewind() {
68 4
    $this->rotation = $this->getDataset();
69 4
  }
70
71
  /**
72
   * {@inheritdoc}
73
   */
74
  public function valid() {
75
    return TRUE;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
76
  }
77
78
  /**
79
   * {@inheritdoc}
80
   */
81 3
  public function count() {
82 3
    return count($this->getDataset());
83
  }
84
85
}
86