ScannerGeneric::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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