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

Rotation::key()   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 2
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 Rotation.
10
 */
11
class Rotation extends Combinatorics implements IteratorInterface
12
{
13
    /**
14
     * The key.
15
     *
16
     * @var int
17
     */
18
    protected $key = 0;
19
20
    /**
21
     * A copy of the original data.
22
     *
23
     * @var mixed[]
24
     */
25
    protected $rotation;
26
27
    /**
28
     * Rotation constructor.
29
     *
30
     * @param array $dataset
31
     *                       The dataset
32
     */
33 5
    public function __construct(array $dataset = [])
34
    {
35 5
        parent::__construct($dataset, null);
36 5
        $this->rotation = $this->getDataset();
37 5
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 5
    public function current()
43
    {
44 5
        return $this->rotation;
45
    }
46
47
    /**
48
     * Compute the next value of the Iterator.
49
     *
50
     * @param int $offset
51
     *                    The offset
52
     */
53 5
    public function next($offset = 1)
54
    {
55 5
        $offset = (null === $offset) ? 1 : $offset % $this->count();
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $offset. This often makes code more readable.
Loading history...
56 5
        $this->rotation = array_merge(array_slice($this->rotation, $offset), array_slice($this->rotation, 0, $offset));
57 5
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 5
    public function rewind()
63
    {
64 5
        $this->rotation = $this->getDataset();
65 5
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function valid()
71
    {
72
        return true;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 5
    public function count()
79
    {
80 5
        return count($this->getDataset());
81
    }
82
}
83