X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FReversedFileReader.php;h=fbd32d51fd4886f25cc165dc65c6ee1d539c55d1;hb=e02c475c9e98f27f631bd245592f1641c181db72;hp=248792f17aa81786f43bda72f9fa49adfce4f797;hpb=7f695197aae9d87f5c04c2f7801d97852d72a3bc;p=friendica.git diff --git a/src/Util/ReversedFileReader.php b/src/Util/ReversedFileReader.php index 248792f17a..fbd32d51fd 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; @@ -72,10 +72,11 @@ 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); @@ -85,8 +86,8 @@ 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() { @@ -95,6 +96,9 @@ class ReversedFileReader implements \Iterator if ($this->pos == 0) { return array_pop($buffer); } + if (is_null($buffer)) { + return null; + } if (count($buffer) > 1) { return array_pop($buffer); } @@ -104,7 +108,7 @@ class ReversedFileReader implements \Iterator /** * Fetch next line from end and set it as current iterator value. - * + * * @see Iterator::next() * @return void */ @@ -116,9 +120,9 @@ class ReversedFileReader implements \Iterator /** * Rewind iterator to the first line at the end of file - * + * * @see Iterator::rewind() - * @return void + * @return void */ public function rewind() { @@ -133,33 +137,33 @@ class ReversedFileReader implements \Iterator /** * Return current line number, starting from zero at the end of file - * + * * @see Iterator::key() * @return int */ - public function key() + public function key(): int { return $this->key; } /** * Return current line - * + * * @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 - * + * * @see Iterator::valid() * @return bool */ - public function valid() + public function valid(): bool { return ! is_null($this->value); }