| Total Complexity | 8 |
| Total Lines | 75 |
| 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 | */ |
||
| 18 | private $data; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var int |
||
| 22 | */ |
||
| 23 | private $offset = 0; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var int |
||
| 27 | */ |
||
| 28 | private $length; |
||
| 29 | |||
| 30 | 20 | public function __construct(int ...$data) |
|
| 31 | { |
||
| 32 | 20 | $this->data = $data; |
|
| 33 | 20 | $this->length = count($data); |
|
| 34 | 20 | } |
|
| 35 | |||
| 36 | /** |
||
| 37 | * {@inheritDoc} |
||
| 38 | * |
||
| 39 | * @return bool |
||
| 40 | * @psalm-pure |
||
| 41 | */ |
||
| 42 | 6 | public function isFinished(): bool |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritDoc} |
||
| 49 | * |
||
| 50 | * @return SymbolInterface |
||
| 51 | */ |
||
| 52 | 14 | public function read(): SymbolInterface |
|
| 53 | { |
||
| 54 | 14 | if ($this->length == $this->offset) { |
|
| 55 | 2 | throw new Exception\UnexpectedEndOfInputException($this->offset); |
|
| 56 | } |
||
| 57 | |||
| 58 | 13 | return new Symbol($this->offset, $this->data[$this->offset++], new NullLexeme()); |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return int |
||
| 63 | * @psalm-pure |
||
| 64 | */ |
||
| 65 | 3 | public function getOffset(): int |
|
| 66 | { |
||
| 67 | 3 | return $this->offset; |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return LexemeInterface |
||
| 72 | * @psalm-pure |
||
| 73 | */ |
||
| 74 | 4 | public function getEmptyLexeme(): LexemeInterface |
|
| 75 | { |
||
| 76 | 4 | return new EmptyLexeme($this->offset, new NullLexeme()); |
|
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return Iterator |
||
| 81 | * @psalm-return Iterator<int,SymbolInterface> |
||
| 82 | */ |
||
| 83 | 3 | public function getIterator(): Iterator |
|
| 87 | } |
||
| 88 | 3 | } |
|
| 89 | } |
||
| 90 |