Skip to content

Commit a5b9e4b

Browse files
committed
Up phpstan baseline
1 parent 982c655 commit a5b9e4b

6 files changed

+16
-34
lines changed

src/ArrayBuffer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ArrayBuffer extends Buffer
1616
/**
1717
* @var int<0, max>
1818
*/
19-
private int $size;
19+
private readonly int $size;
2020

2121
/**
2222
* @param iterable<int<0, max>, TokenInterface> $stream
@@ -45,7 +45,7 @@ private function iterableToArray(iterable $tokens): array
4545
return $tokens;
4646
}
4747

48-
public function seek($offset): void
48+
public function seek(int $offset): void
4949
{
5050
if ($offset < $this->initial) {
5151
throw new \OutOfRangeException(

src/Buffer.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function rewind(): void
5151
$this->seek($this->initial);
5252
}
5353

54-
public function seek($offset): void
54+
public function seek(int $offset): void
5555
{
5656
\assert($offset >= 0);
5757

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

6161
/**
6262
* @param array<TokenInterface> $data
63-
*
64-
* @psalm-suppress PossiblyNullArrayOffset
6563
*/
6664
protected function currentFrom(array $data): TokenInterface
6765
{

src/BufferInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface BufferInterface extends \SeekableIterator
2020
*
2121
* @param int<0, max> $offset
2222
*/
23-
public function seek($offset): void;
23+
public function seek(int $offset): void;
2424

2525
/**
2626
* Return the current token.

src/ExtrusiveBuffer.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,17 @@ class ExtrusiveBuffer extends LazyBuffer
2020
*/
2121
public const BUFFER_DEFAULT_SIZE = 100;
2222

23-
/**
24-
* @var int<1, max>
25-
*/
26-
private int $size;
27-
2823
/**
2924
* @param iterable<TokenInterface> $stream
30-
* @param int<1, max> $size
3125
*/
3226
public function __construct(
3327
iterable $stream,
34-
int $size = self::BUFFER_DEFAULT_SIZE
28+
/**
29+
* @var int<1, max>
30+
*/
31+
private readonly int $size = self::BUFFER_DEFAULT_SIZE,
3532
) {
36-
$this->size = $size;
37-
38-
/** @psalm-suppress RedundantCondition */
39-
assert($this->size > 0, 'Buffer size must be greater than 0, but ' . $size . ' passed');
33+
assert($this->size > 0, 'Buffer size must be greater than 0, but ' . $this->size . ' passed');
4034

4135
parent::__construct($stream);
4236
}
@@ -49,7 +43,7 @@ public function getBufferSize(): int
4943
return $this->size;
5044
}
5145

52-
public function seek($offset): void
46+
public function seek(int $offset): void
5347
{
5448
if ($offset < \array_key_first($this->buffer)) {
5549
$message = \sprintf(self::ERROR_BUFFER_MEMORY_ALREADY_FREED, $offset, $this->size);
@@ -63,7 +57,6 @@ public function seek($offset): void
6357
public function next(): void
6458
{
6559
if ($this->nextValid() && $this->getBufferCurrentSize() > $this->size) {
66-
/** @psalm-suppress PossiblyNullArrayOffset */
6760
unset($this->buffer[\array_key_first($this->buffer)]);
6861
}
6962
}

src/LazyBuffer.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ class LazyBuffer extends Buffer
2323
*/
2424
public function __construct(iterable $stream)
2525
{
26-
/** @psalm-suppress MixedPropertyTypeCoercion */
2726
$this->stream = $this->toGenerator($stream);
2827

2928
if ($this->stream->valid()) {
30-
/** @psalm-suppress MixedAssignment */
3129
$this->initial = $this->current = $this->stream->key();
32-
/** @psalm-suppress MixedArrayOffset */
3330
$this->buffer[$this->current] = $this->stream->current();
3431

3532
$this->stream->next();
@@ -54,7 +51,7 @@ public function getBufferCurrentSize(): int
5451
return \count($this->buffer);
5552
}
5653

57-
public function seek($offset): void
54+
public function seek(int $offset): void
5855
{
5956
if ($offset < $this->initial) {
6057
throw new \OutOfRangeException(
@@ -102,7 +99,7 @@ protected function nextValid(): bool
10299
if (!isset($this->buffer[$this->current])) {
103100
$current = $this->stream->current();
104101

105-
if ($current) {
102+
if ((bool) $current) {
106103
$this->buffer[$this->current] = $current;
107104
$this->stream->next();
108105

@@ -113,9 +110,6 @@ protected function nextValid(): bool
113110
return false;
114111
}
115112

116-
/**
117-
* @psalm-suppress MixedReturnTypeCoercion
118-
*/
119113
public function key(): int
120114
{
121115
if (!$this->valid()) {

src/MutableBuffer.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@
1010
*/
1111
class MutableBuffer implements BufferInterface
1212
{
13-
private BufferInterface $parent;
14-
1513
/**
1614
* @var array<int<0, max>, TokenInterface>
1715
*/
1816
private array $overrides = [];
1917

20-
public function __construct(BufferInterface $parent)
21-
{
22-
$this->parent = $parent;
23-
}
18+
public function __construct(
19+
private readonly BufferInterface $parent,
20+
) {}
2421

2522
/**
2623
* @param int<0, max> $offset
@@ -54,7 +51,7 @@ private function poll(int $offset): TokenInterface
5451
}
5552
}
5653

57-
public function seek($offset): void
54+
public function seek(int $offset): void
5855
{
5956
$this->parent->seek($offset);
6057
}

0 commit comments

Comments
 (0)