Completed
Push — master ( a49478...ff8a6e )
by Pol
01:00 queued 10s
created

Cycle   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 58.33%

Importance

Changes 0
Metric Value
wmc 5
cbo 1
dl 0
loc 49
ccs 7
cts 12
cp 0.5833
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
A count() 0 4 1
1
<?php
2
3
namespace drupol\phpermutations\Iterators;
4
5
use drupol\phpermutations\Combinatorics;
6
use drupol\phpermutations\IteratorInterface;
7
8
/**
9
 * Class Cycle.
10
 */
11
class Cycle extends Combinatorics implements IteratorInterface
12
{
13
    /**
14
     * The key.
15
     *
16
     * @var int
17
     */
18
    protected $key = 0;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 3
    public function current()
24
    {
25 3
        return $this->dataset[$this->key];
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 3
    public function next()
32
    {
33 3
        $this->key = ($this->key + 1) % $this->datasetCount;
34 3
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function rewind()
40
    {
41
        $this->key = 0;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function valid()
48
    {
49
        return true;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 3
    public function count()
56
    {
57 3
        return count($this->getDataset());
58
    }
59
}
60