X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FReversedFileReader.php;h=58fb2cb3faaceab460c86ed8192cb103625725fe;hb=e1863951986ba5be173758324a00652bc5af870c;hp=bdc31f0cba158f3b5f86796cd54ed8fb537f8d41;hpb=632d1024f7e0e04eb568a22e06c8a12a3c89d74e;p=friendica.git diff --git a/src/Util/ReversedFileReader.php b/src/Util/ReversedFileReader.php index bdc31f0cba..58fb2cb3fa 100644 --- a/src/Util/ReversedFileReader.php +++ b/src/Util/ReversedFileReader.php @@ -1,6 +1,6 @@ fh = fopen($filename, 'r'); if (!$this->fh) { // this should use a custom exception. - throw \Exception("Unable to open $filename"); + throw new \Exception("Unable to open $filename"); } $this->filesize = filesize($filename); $this->pos = -1; @@ -73,9 +73,10 @@ class ReversedFileReader implements \Iterator /** * Read $size bytes behind last position * + * @param int $size * @return string */ - private function _read($size) + private function _read(int $size): string { $this->pos -= $size; fseek($this->fh, $this->pos); @@ -86,15 +87,18 @@ class ReversedFileReader implements \Iterator * Read next line from end of file * Return null if no lines are left to read * - * @return ?string + * @return string|null Depending on data being buffered */ - private function _readline() + private function _readline(): ?string { $buffer = & $this->buffer; while (true) { if ($this->pos == 0) { return array_pop($buffer); } + if (is_null($buffer)) { + return null; + } if (count($buffer) > 1) { return array_pop($buffer); } @@ -108,6 +112,7 @@ class ReversedFileReader implements \Iterator * @see Iterator::next() * @return void */ + #[\ReturnTypeWillChange] public function next() { ++$this->key; @@ -120,6 +125,7 @@ class ReversedFileReader implements \Iterator * @see Iterator::rewind() * @return void */ + #[\ReturnTypeWillChange] public function rewind() { if ($this->filesize > 0) { @@ -137,7 +143,7 @@ class ReversedFileReader implements \Iterator * @see Iterator::key() * @return int */ - public function key() + public function key(): int { return $this->key; } @@ -148,18 +154,18 @@ class ReversedFileReader implements \Iterator * @see Iterator::current() * @return string */ - public function current() + public function current(): string { return $this->value; } /** - * Checks if current iterator value is valid, that is, we readed all lines in files + * Checks if current iterator value is valid, that is, we read all lines in files * * @see Iterator::valid() * @return bool */ - public function valid() + public function valid(): bool { return ! is_null($this->value); }