| @@ -9,8 +9,10 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | class HashingStream implements StreamInterface |
| 11 | 11 | { |
| 12 | 12 | use StreamDecoratorTrait; |
| 13 | + /** @var StreamInterface */ | |
| 14 | + private $stream; | |
| 13 | 15 | /** @var HashInterface */ |
| 14 | 16 | private $hash; |
| 15 | 17 | /** @var callable|null */ |
| 16 | 18 | private $callback; |
| @@ -19,15 +21,15 @@ | ||
| 19 | 21 | * @param HashInterface $hash Hash used to calculate checksum. |
| 20 | 22 | * @param callable $onComplete Optional function invoked when the |
| 21 | 23 | * hash calculation is completed. |
| 22 | 24 | */ |
| 23 | - public function __construct(StreamInterface $stream, HashInterface $hash, callable $onComplete = null) | |
| 25 | + public function __construct(StreamInterface $stream, HashInterface $hash, ?callable $onComplete = null) | |
| 24 | 26 | { |
| 25 | 27 | $this->stream = $stream; |
| 26 | 28 | $this->hash = $hash; |
| 27 | 29 | $this->callback = $onComplete; |
| 28 | 30 | } |
| 29 | - public function read($length) | |
| 31 | + public function read($length) : string | |
| 30 | 32 | { |
| 31 | 33 | $data = $this->stream->read($length); |
| 32 | 34 | $this->hash->update($data); |
| 33 | 35 | if ($this->eof()) { |
| @@ -37,14 +39,14 @@ | ||
| 37 | 39 | } |
| 38 | 40 | } |
| 39 | 41 | return $data; |
| 40 | 42 | } |
| 41 | - public function seek($offset, $whence = \SEEK_SET) | |
| 43 | + public function seek($offset, $whence = \SEEK_SET) : void | |
| 42 | 44 | { |
| 43 | - if ($offset === 0) { | |
| 44 | - $this->hash->reset(); | |
| 45 | - return $this->stream->seek($offset); | |
| 45 | + // Seeking arbitrarily is not supported. | |
| 46 | + if ($offset !== 0) { | |
| 47 | + return; | |
| 46 | 48 | } |
| 47 | - // Seeking arbitrarily is not supported. | |
| 48 | - return \false; | |
| 49 | + $this->hash->reset(); | |
| 50 | + $this->stream->seek($offset); | |
| 49 | 51 | } |
| 50 | 52 | } |