Completed
Push — master ( ee6b13...b11566 )
by Pol
04:05
created

Cycle::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace drupol\phpermutations\Iterators;
4
5
use drupol\phpermutations\Combinatorics;
6
7
/**
8
 * Class Cycle.
9
 *
10
 * @package drupol\phpermutations\Iterators
11
 */
12
class Cycle extends Combinatorics implements \Iterator, \Countable {
13
14
  /**
15
   * The key.
16
   *
17
   * @var int
18
   */
19
  protected $key = 0;
20
21
  /**
22
   * Cycle constructor.
23
   *
24
   * @param array $dataset
25
   *   The dataset.
26
   */
27 1
  public function __construct(array $dataset = array()) {
28 1
    parent::__construct($dataset);
29 1
  }
30
31
  /**
32
   * {@inheritdoc}
33
   */
34
  public function key() {
35
    return $this->key;
36
  }
37
38
  /**
39
   * {@inheritdoc}
40
   */
41 1
  public function current() {
42 1
    return $this->dataset[$this->key];
43
  }
44
45
  /**
46
   * {@inheritdoc}
47
   */
48 1
  public function next() {
49 1
    $this->key = ($this->key + 1) % $this->datasetCount;
50 1
  }
51
52
  /**
53
   * {@inheritdoc}
54
   */
55
  public function rewind() {
56
    $this->key = 0;
57
  }
58
59
  /**
60
   * {@inheritdoc}
61
   */
62
  public function valid() {
63
    return TRUE;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
64
  }
65
66
  /**
67
   * {@inheritdoc}
68
   */
69 1
  public function count() {
70 1
    return count($this->getDataset());
71
  }
72
73
}
74