Completed
Push — master ( b0b79e...9ac4d8 )
by Hans
18s
created

ScannerGeneric::peek()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.0625
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 105
    public function __construct(array $items)
11
    {
12 105
        $this->items = $items;
13 105
    }
14
15 102
    public function peek()
16
    {
17 102
        if (isset($this->items[$this->position + 1]) === false) {
18
            throw new ScannerReachedEnd('Unable to peek because scanner reached end');
19
        }
20
21 102
        return $this->items[$this->position + 1];
22
    }
23
24 102
    public function next()
25
    {
26 102 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 102
        $this->position++;
32
33 102
        return $this->items[$this->position];
34
    }
35
36 105
    public function eof()
37
    {
38 105
        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