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

Cycle::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
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
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