Completed
Push — master ( 15a3ff...ddeb31 )
by Pol
02:16
created

Cycle::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
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;
4
5
/**
6
 * Class Cycle.
7
 *
8
 * @package drupol\phpermutations
9
 */
10
class Cycle extends Combinatorics implements \Iterator {
11
12
  /**
13
   * @var array
14
   */
15
  protected $c = array();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $c. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
16
17
  /**
18
   * @var int
19
   */
20
  protected $count = 0;
21
22
  /**
23
   * @var int
24
   */
25
  protected $pos = 0;
26
27
  /**
28
   * Cycle constructor.
29
   *
30
   * @param array $dataset
31
   */
32 1
  public function __construct(array $dataset = array()) {
33 1
    parent::__construct($dataset);
34 1
    $this->rewind();
35 1
  }
36
37
  /**
38
   * @return int
39
   */
40
  public function key() {
41
    return $this->pos;
42
  }
43
44
  /**
45
   * @return array
46
   */
47
  public function current() {
48
    return $this->dataset[$this->pos];
49
  }
50
51
  /**
52
   *
53
   */
54
  public function next() {
55
    $this->pos = ($this->pos + 1) % $this->datasetCount;
56
  }
57
58
  /**
59
   *
60
   */
61 1
  public function rewind() {
62 1
    $this->pos = 0;
63 1
  }
64
65
  /**
66
   * @return bool
67
   */
68
  public function valid() {
69
    return TRUE;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected true, but found TRUE.
Loading history...
70
  }
71
72
  /**
73
   * @return int
74
   */
75 1
  public function count() {
76 1
    return count($this->getDataset());
77
  }
78
79
}
80