diff --git a/src/ArrayBuffer.php b/src/ArrayBuffer.php index 91d2b53..3f70654 100644 --- a/src/ArrayBuffer.php +++ b/src/ArrayBuffer.php @@ -16,7 +16,7 @@ class ArrayBuffer extends Buffer /** * @var int<0, max> */ - private int $size; + private readonly int $size; /** * @param iterable, TokenInterface> $stream @@ -45,7 +45,7 @@ private function iterableToArray(iterable $tokens): array return $tokens; } - public function seek($offset): void + public function seek(int $offset): void { if ($offset < $this->initial) { throw new \OutOfRangeException( diff --git a/src/Buffer.php b/src/Buffer.php index ece21f7..037ea21 100644 --- a/src/Buffer.php +++ b/src/Buffer.php @@ -51,7 +51,7 @@ public function rewind(): void $this->seek($this->initial); } - public function seek($offset): void + public function seek(int $offset): void { \assert($offset >= 0); @@ -60,8 +60,6 @@ public function seek($offset): void /** * @param array $data - * - * @psalm-suppress PossiblyNullArrayOffset */ protected function currentFrom(array $data): TokenInterface { diff --git a/src/BufferInterface.php b/src/BufferInterface.php index c69ebba..f0bf313 100644 --- a/src/BufferInterface.php +++ b/src/BufferInterface.php @@ -20,7 +20,7 @@ interface BufferInterface extends \SeekableIterator * * @param int<0, max> $offset */ - public function seek($offset): void; + public function seek(int $offset): void; /** * Return the current token. diff --git a/src/ExtrusiveBuffer.php b/src/ExtrusiveBuffer.php index 5e96eab..303ed6a 100644 --- a/src/ExtrusiveBuffer.php +++ b/src/ExtrusiveBuffer.php @@ -20,23 +20,17 @@ class ExtrusiveBuffer extends LazyBuffer */ public const BUFFER_DEFAULT_SIZE = 100; - /** - * @var int<1, max> - */ - private int $size; - /** * @param iterable $stream - * @param int<1, max> $size */ public function __construct( iterable $stream, - int $size = self::BUFFER_DEFAULT_SIZE + /** + * @var int<1, max> + */ + private readonly int $size = self::BUFFER_DEFAULT_SIZE, ) { - $this->size = $size; - - /** @psalm-suppress RedundantCondition */ - assert($this->size > 0, 'Buffer size must be greater than 0, but ' . $size . ' passed'); + assert($this->size > 0, 'Buffer size must be greater than 0, but ' . $this->size . ' passed'); parent::__construct($stream); } @@ -49,7 +43,7 @@ public function getBufferSize(): int return $this->size; } - public function seek($offset): void + public function seek(int $offset): void { if ($offset < \array_key_first($this->buffer)) { $message = \sprintf(self::ERROR_BUFFER_MEMORY_ALREADY_FREED, $offset, $this->size); @@ -63,7 +57,6 @@ public function seek($offset): void public function next(): void { if ($this->nextValid() && $this->getBufferCurrentSize() > $this->size) { - /** @psalm-suppress PossiblyNullArrayOffset */ unset($this->buffer[\array_key_first($this->buffer)]); } } diff --git a/src/LazyBuffer.php b/src/LazyBuffer.php index 9c5ac3f..3cc4560 100644 --- a/src/LazyBuffer.php +++ b/src/LazyBuffer.php @@ -23,13 +23,10 @@ class LazyBuffer extends Buffer */ public function __construct(iterable $stream) { - /** @psalm-suppress MixedPropertyTypeCoercion */ $this->stream = $this->toGenerator($stream); if ($this->stream->valid()) { - /** @psalm-suppress MixedAssignment */ $this->initial = $this->current = $this->stream->key(); - /** @psalm-suppress MixedArrayOffset */ $this->buffer[$this->current] = $this->stream->current(); $this->stream->next(); @@ -54,7 +51,7 @@ public function getBufferCurrentSize(): int return \count($this->buffer); } - public function seek($offset): void + public function seek(int $offset): void { if ($offset < $this->initial) { throw new \OutOfRangeException( @@ -102,7 +99,7 @@ protected function nextValid(): bool if (!isset($this->buffer[$this->current])) { $current = $this->stream->current(); - if ($current) { + if ((bool) $current) { $this->buffer[$this->current] = $current; $this->stream->next(); @@ -113,9 +110,6 @@ protected function nextValid(): bool return false; } - /** - * @psalm-suppress MixedReturnTypeCoercion - */ public function key(): int { if (!$this->valid()) { diff --git a/src/MutableBuffer.php b/src/MutableBuffer.php index 0de7d9f..82cf94d 100644 --- a/src/MutableBuffer.php +++ b/src/MutableBuffer.php @@ -10,17 +10,14 @@ */ class MutableBuffer implements BufferInterface { - private BufferInterface $parent; - /** * @var array, TokenInterface> */ private array $overrides = []; - public function __construct(BufferInterface $parent) - { - $this->parent = $parent; - } + public function __construct( + private readonly BufferInterface $parent, + ) {} /** * @param int<0, max> $offset @@ -54,7 +51,7 @@ private function poll(int $offset): TokenInterface } } - public function seek($offset): void + public function seek(int $offset): void { $this->parent->seek($offset); }