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

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