Skip to content

Commit

Permalink
Up phpstan baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
SerafimArts committed Sep 11, 2024
1 parent 982c655 commit a5b9e4b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/ArrayBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ArrayBuffer extends Buffer
/**
* @var int<0, max>
*/
private int $size;
private readonly int $size;

/**
* @param iterable<int<0, max>, TokenInterface> $stream
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions src/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -60,8 +60,6 @@ public function seek($offset): void

/**
* @param array<TokenInterface> $data
*
* @psalm-suppress PossiblyNullArrayOffset
*/
protected function currentFrom(array $data): TokenInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/BufferInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 6 additions & 13 deletions src/ExtrusiveBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,17 @@ class ExtrusiveBuffer extends LazyBuffer
*/
public const BUFFER_DEFAULT_SIZE = 100;

/**
* @var int<1, max>
*/
private int $size;

/**
* @param iterable<TokenInterface> $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);
}
Expand All @@ -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);
Expand All @@ -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)]);
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/LazyBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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();

Expand All @@ -113,9 +110,6 @@ protected function nextValid(): bool
return false;
}

/**
* @psalm-suppress MixedReturnTypeCoercion
*/
public function key(): int
{
if (!$this->valid()) {
Expand Down
11 changes: 4 additions & 7 deletions src/MutableBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
*/
class MutableBuffer implements BufferInterface
{
private BufferInterface $parent;

/**
* @var array<int<0, max>, TokenInterface>
*/
private array $overrides = [];

public function __construct(BufferInterface $parent)
{
$this->parent = $parent;
}
public function __construct(
private readonly BufferInterface $parent,
) {}

/**
* @param int<0, max> $offset
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a5b9e4b

Please sign in to comment.