NGrams   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 54
ccs 13
cts 16
cp 0.8125
rs 10

4 Methods

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