Passed
Push — master ( 1e7555...a49478 )
by Pol
03:09
created

NGrams   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 4
cbo 1
dl 0
loc 47
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A next() 0 5 1
A rewind() 0 5 1
A current() 0 4 1
1
<?php
2
3
namespace drupol\phpermutations\Iterators;
4
5
/**
6
 * Class NGrams.
7
 */
8
class NGrams extends Shift implements \Iterator, \Countable
9
{
10
    /**
11
     * @var
12
     */
13
    protected $currentValue;
14
15
    /**
16
     * NGrams constructor.
17
     *
18
     * @param array $dataset
19
     *                       The dataset
20
     * @param int   $length
21
     *                       The shift length
22
     */
23 4
    public function __construct(array $dataset = [], $length = 1)
24
    {
25 4
        parent::__construct($dataset, $length);
26 4
        $this->currentValue = array_slice(($this->getDataset()), 0, $length);
27 4
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 4
    public function next()
33
    {
34 4
        parent::next();
35 4
        $this->currentValue = array_slice($this->current, 0, $this->getLength());
36 4
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function rewind()
42
    {
43
        parent::rewind();
44
        $this->currentValue = array_slice($this->current, 0, $this->getLength());
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 4
    public function current()
51
    {
52 4
        return $this->currentValue;
53
    }
54
}
55