ScannerGeneric   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 76.19%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 8
loc 48
ccs 16
cts 21
cp 0.7619
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A peek() 0 8 2
A next() 4 11 2
A eof() 0 4 1
A back() 4 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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