Total Complexity | 12 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class SourceBuffer implements Iterator |
||
11 | { |
||
12 | protected $source; |
||
13 | protected $bufferMaxSize; |
||
14 | protected $bufferSize; |
||
15 | protected $buffer; |
||
16 | protected $bufferPosition; |
||
17 | protected $sourcePosition; |
||
18 | |||
19 | 118 | public function __construct(SourceInterface $source, int $bufferSize = 4096) |
|
20 | { |
||
21 | 118 | $this->source = $source; |
|
22 | 118 | $this->bufferMaxSize = $bufferSize; |
|
23 | 118 | $this->sourcePosition = 0; |
|
24 | 118 | } |
|
25 | |||
26 | 116 | protected function nextBuffer() |
|
34 | } |
||
35 | 116 | } |
|
36 | |||
37 | 114 | public function current() |
|
38 | { |
||
39 | 114 | if (!$this->valid()) { |
|
40 | 1 | return null; |
|
41 | } |
||
42 | |||
43 | 113 | return $this->buffer[$this->bufferPosition]; |
|
44 | } |
||
45 | |||
46 | 112 | public function next() |
|
47 | { |
||
48 | 112 | $this->bufferPosition++; |
|
49 | 112 | if ($this->bufferPosition == min($this->bufferMaxSize, $this->bufferSize)) { |
|
50 | 112 | $this->nextBuffer(); |
|
51 | } |
||
52 | 112 | if ($this->buffer !== null) { |
|
53 | 103 | $this->sourcePosition++; |
|
54 | } |
||
55 | 112 | } |
|
56 | |||
57 | 4 | public function key() |
|
60 | } |
||
61 | |||
62 | 118 | public function valid() |
|
63 | { |
||
64 | 118 | return $this->buffer !== null |
|
65 | 118 | && $this->bufferPosition < $this->bufferSize; |
|
66 | } |
||
67 | |||
68 | 116 | public function rewind() |
|
72 | 116 | } |
|
73 | } |
||
74 |