NGrams::rewind()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\phpermutations\Iterators;
6
7
use function array_slice;
8
9
class NGrams extends Shift
10
{
11
    /**
12
     * @var mixed
13
     */
14
    protected $currentValue;
15
16
    /**
17
     * NGrams constructor.
18
     *
19
     * @param array<int, mixed> $dataset
20
     *                       The dataset
21
     * @param int   $length
22
     *                       The shift length
23
     */
24 4
    public function __construct(array $dataset = [], $length = 1)
25
    {
26 4
        parent::__construct($dataset, $length);
27
28 4
        $this->currentValue = array_slice(
29 4
            $this->getDataset(),
30 4
            0,
31 4
            $length
32
        );
33 4
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 4
    public function current(): mixed
39
    {
40 4
        return $this->currentValue;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     *
46
     * @return void
47
     */
48 4
    public function next(): void
49
    {
50 4
        parent::next();
51 4
        $this->currentValue = array_slice($this->current, 0, $this->getLength());
52 4
    }
53
54
    /**
55
     * {@inheritdoc}
56
     *
57
     * @return void
58
     */
59
    public function rewind(): void
60
    {
61
        parent::rewind();
62
        $this->currentValue = array_slice($this->current, 0, $this->getLength());
63
    }
64
}
65