| Conditions | 7 |
| Paths | 10 |
| Total Lines | 23 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | public function getIterator():Iterator |
||
| 37 | { |
||
| 38 | if (file_exists($this->path) && ($fp = fopen($this->path, 'rb')) !== false) { |
||
| 39 | $offset = 0; |
||
| 40 | while (!feof($fp)) { |
||
| 41 | fseek($fp, $offset); |
||
| 42 | $content = fread($fp, $this->bufferSize); |
||
| 43 | $content.=(feof($fp))? "\n":''; |
||
| 44 | $size = strpos($content, "\n"); |
||
| 45 | $offset += $size; |
||
| 46 | if ($content[$size - 1] === "\r") { |
||
| 47 | $content = substr($content, 0, $size -1); |
||
| 48 | } else { |
||
| 49 | $content = substr($content, 0, $size); |
||
| 50 | } |
||
| 51 | if (is_null($this->offset)) { |
||
| 52 | yield $content; |
||
| 53 | } else { |
||
| 54 | yield $offset => $content; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | throw new \Exception(sprintf('readline iterator: file note exists %s', $this->path)); |
||
| 59 | } |
||
| 62 |