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

Cycle   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 7
cbo 1
dl 0
loc 70
ccs 9
cts 18
cp 0.5
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 3 1
A rewind() 0 3 1
A valid() 0 3 1
A count() 0 3 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