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

Rotation   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 7
cbo 1
dl 0
loc 72
ccs 15
cts 17
cp 0.8824
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A current() 0 4 1
A next() 0 5 2
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 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