- added type-hints
- added documentation
This commit is contained in:
Roland Häder 2022-06-24 06:27:38 +02:00
parent 804b759df1
commit 4164cdacf5
No known key found for this signature in database
GPG key ID: C82EDE5DDFA0BA77

View file

@ -55,7 +55,7 @@ class ReversedFileReader implements \Iterator
* @param string $filename File to open * @param string $filename File to open
* @return $this * @return $this
*/ */
public function open(string $filename) public function open(string $filename): ReversedFileReader
{ {
$this->fh = fopen($filename, 'r'); $this->fh = fopen($filename, 'r');
if (!$this->fh) { if (!$this->fh) {
@ -73,9 +73,10 @@ class ReversedFileReader implements \Iterator
/** /**
* Read $size bytes behind last position * Read $size bytes behind last position
* *
* @param int $size
* @return string * @return string
*/ */
private function _read($size) private function _read(int $size): string
{ {
$this->pos -= $size; $this->pos -= $size;
fseek($this->fh, $this->pos); fseek($this->fh, $this->pos);
@ -86,7 +87,7 @@ class ReversedFileReader implements \Iterator
* Read next line from end of file * Read next line from end of file
* Return null if no lines are left to read * 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()
{ {
@ -140,7 +141,7 @@ class ReversedFileReader implements \Iterator
* @see Iterator::key() * @see Iterator::key()
* @return int * @return int
*/ */
public function key() public function key(): int
{ {
return $this->key; return $this->key;
} }
@ -151,7 +152,7 @@ class ReversedFileReader implements \Iterator
* @see Iterator::current() * @see Iterator::current()
* @return string * @return string
*/ */
public function current() public function current(): string
{ {
return $this->value; return $this->value;
} }
@ -162,7 +163,7 @@ class ReversedFileReader implements \Iterator
* @see Iterator::valid() * @see Iterator::valid()
* @return bool * @return bool
*/ */
public function valid() public function valid(): bool
{ {
return ! is_null($this->value); return ! is_null($this->value);
} }