ScannerGeneric::next()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 4
Ratio 36.36 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 0
Metric Value
dl 4
loc 11
ccs 4
cts 6
cp 0.6667
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2.1481
1
<?php
2
3
namespace HansOtt\GraphQL\Shared;
4
5
final class ScannerGeneric implements Scanner
6
{
7
    private $items;
8
    private $position = -1;
9
10 111
    public function __construct(array $items)
11
    {
12 111
        $this->items = $items;
13 111
    }
14
15 108
    public function peek()
16
    {
17 108
        if (isset($this->items[$this->position + 1]) === false) {
18
            throw new ScannerReachedEnd('Unable to peek because scanner reached end');
19
        }
20
21 108
        return $this->items[$this->position + 1];
22
    }
23
24 108
    public function next()
25
    {
26 108 View Code Duplication
        if (isset($this->items[$this->position + 1]) === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
            $nextPosition = $this->position + 1;
28
            throw new ScannerReachedEnd("Tried to move to position {$nextPosition} but reached end");
29
        }
30
31 108
        $this->position++;
32
33 108
        return $this->items[$this->position];
34
    }
35
36 111
    public function eof()
37
    {
38 111
        return isset($this->items[$this->position + 1]) === false;
39
    }
40
41 3
    public function back()
42
    {
43 3 View Code Duplication
        if (isset($this->items[$this->position - 1]) === false) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            $nextPosition = $this->position - 1;
45
            throw new ScannerReachedEnd("Tried to move to position {$nextPosition} but reached end");
46
        }
47
48 3
        $this->position--;
49
50 3
        return $this->items[$this->position];
51
    }
52
}
53