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

Rotation::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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