Total Complexity | 8 |
Total Lines | 80 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | final class ArrayInput implements IteratorAggregate, SymbolReaderInterface |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @var int[] |
||
17 | * @psalm-var array<int, int> |
||
18 | */ |
||
19 | private $data; |
||
20 | |||
21 | /** |
||
22 | * @var int |
||
23 | */ |
||
24 | private $offset = 0; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $length; |
||
30 | |||
31 | 20 | public function __construct(int ...$data) |
|
32 | { |
||
33 | 20 | $this->data = $data; |
|
34 | 20 | $this->length = count($data); |
|
35 | 20 | } |
|
36 | |||
37 | /** |
||
38 | * {@inheritDoc} |
||
39 | * |
||
40 | * @return bool |
||
41 | * @psalm-pure |
||
42 | */ |
||
43 | 6 | public function isFinished(): bool |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | * |
||
51 | * @return SymbolInterface |
||
52 | */ |
||
53 | 14 | public function read(): SymbolInterface |
|
54 | { |
||
55 | 14 | if ($this->length == $this->offset) { |
|
56 | 2 | throw new Exception\UnexpectedEndOfInputException($this->offset); |
|
57 | } |
||
58 | |||
59 | 13 | return new Symbol($this->offset, $this->data[$this->offset++], new NullLexeme()); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritDoc} |
||
64 | * |
||
65 | * @return int |
||
66 | * @psalm-pure |
||
67 | */ |
||
68 | 3 | public function getOffset(): int |
|
69 | { |
||
70 | 3 | return $this->offset; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritDoc} |
||
75 | * |
||
76 | * @return LexemeInterface |
||
77 | * @psalm-pure |
||
78 | */ |
||
79 | 4 | public function getEmptyLexeme(): LexemeInterface |
|
80 | { |
||
81 | 4 | return new EmptyLexeme($this->offset, new NullLexeme()); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return Iterator |
||
86 | * @psalm-return Iterator<int, SymbolInterface> |
||
87 | */ |
||
88 | 3 | public function getIterator(): Iterator |
|
92 | } |
||
93 | 3 | } |
|
94 | } |
||
95 |