From 5b26a694bfa1f67d6b859e668e9de1590aa02864 Mon Sep 17 00:00:00 2001 From: Zaahid Bateson Date: Wed, 27 Mar 2024 15:26:46 -0700 Subject: [PATCH] Strongly-typed member variables --- src/Base64Stream.php | 8 ++++---- src/CharsetStream.php | 14 +++++++------- src/ChunkSplitStream.php | 11 ++++++----- src/NonClosingStream.php | 3 +-- src/PregReplaceFilterStream.php | 8 ++++---- src/QuotedPrintableStream.php | 6 +++--- src/SeekingLimitStream.php | 16 +++++++--------- 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/Base64Stream.php b/src/Base64Stream.php index c068bb5..7b79c55 100644 --- a/src/Base64Stream.php +++ b/src/Base64Stream.php @@ -47,23 +47,23 @@ class Base64Stream implements StreamInterface /** * @var BufferStream buffered bytes */ - private $buffer; + private BufferStream $buffer; /** * @var string remainder of write operation if the bytes didn't align to 3 * bytes */ - private $remainder = ''; + private string $remainder = ''; /** * @var int current number of read/written bytes (for tell()) */ - private $position = 0; + private int $position = 0; /** * @var StreamInterface $stream */ - private $stream; + private StreamInterface $stream; public function __construct(StreamInterface $stream) { diff --git a/src/CharsetStream.php b/src/CharsetStream.php index a1acb14..a517040 100644 --- a/src/CharsetStream.php +++ b/src/CharsetStream.php @@ -24,39 +24,39 @@ class CharsetStream implements StreamInterface /** * @var MbWrapper the charset converter */ - protected $converter = null; + protected MbWrapper $converter; /** * @var string charset of the source stream */ - protected $streamCharset = 'ISO-8859-1'; + protected string $streamCharset = 'ISO-8859-1'; /** * @var string charset of strings passed in write operations, and returned * in read operations. */ - protected $stringCharset = 'UTF-8'; + protected string $stringCharset = 'UTF-8'; /** * @var int current read/write position */ - private $position = 0; + private int $position = 0; /** * @var int number of $stringCharset characters in $buffer */ - private $bufferLength = 0; + private int $bufferLength = 0; /** * @var string a buffer of characters read in the original $streamCharset * encoding */ - private $buffer = ''; + private string $buffer = ''; /** * @var StreamInterface $stream */ - private $stream; + private StreamInterface $stream; /** * @param StreamInterface $stream Stream to decorate diff --git a/src/ChunkSplitStream.php b/src/ChunkSplitStream.php index fd370de..f90bed4 100644 --- a/src/ChunkSplitStream.php +++ b/src/ChunkSplitStream.php @@ -25,31 +25,32 @@ class ChunkSplitStream implements StreamInterface * final $lineEnding on close (and so maintained instead of using * tell() directly) */ - private $position; + private int $position; /** * @var int The number of characters in a line before inserting $lineEnding. */ - private $lineLength; + private int $lineLength; /** * @var string The line ending characters to insert. */ - private $lineEnding; + private string $lineEnding; /** * @var int The strlen() of $lineEnding */ - private $lineEndingLength; + private int $lineEndingLength; /** * @var StreamInterface $stream */ - private $stream; + private StreamInterface $stream; public function __construct(StreamInterface $stream, int $lineLength = 76, string $lineEnding = "\r\n") { $this->stream = $stream; + $this->position = 0; $this->lineLength = $lineLength; $this->lineEnding = $lineEnding; $this->lineEndingLength = \strlen($this->lineEnding); diff --git a/src/NonClosingStream.php b/src/NonClosingStream.php index 5a7f132..77bf6ff 100644 --- a/src/NonClosingStream.php +++ b/src/NonClosingStream.php @@ -44,7 +44,7 @@ class NonClosingStream implements StreamInterface * @var ?StreamInterface $stream * @phpstan-ignore-next-line */ - private $stream; + private ?StreamInterface $stream; /** * @inheritDoc @@ -62,7 +62,6 @@ public function close() : void public function detach() { $this->stream = null; // @phpstan-ignore-line - return null; } } diff --git a/src/PregReplaceFilterStream.php b/src/PregReplaceFilterStream.php index 4abb492..74fd5d4 100644 --- a/src/PregReplaceFilterStream.php +++ b/src/PregReplaceFilterStream.php @@ -27,22 +27,22 @@ class PregReplaceFilterStream implements StreamInterface /** * @var string The regex pattern */ - private $pattern; + private string $pattern; /** * @var string The replacement */ - private $replacement; + private string $replacement; /** * @var BufferStream Buffered stream of input from the underlying stream */ - private $buffer; + private BufferStream $buffer; /** * @var StreamInterface $stream */ - private $stream; + private StreamInterface $stream; public function __construct(StreamInterface $stream, string $pattern, string $replacement) { diff --git a/src/QuotedPrintableStream.php b/src/QuotedPrintableStream.php index 3a740dd..89fab31 100644 --- a/src/QuotedPrintableStream.php +++ b/src/QuotedPrintableStream.php @@ -23,18 +23,18 @@ class QuotedPrintableStream implements StreamInterface /** * @var int current read/write position */ - private $position = 0; + private int $position = 0; /** * @var string Last line of written text (used to maintain good line-breaks) */ - private $lastLine = ''; + private string $lastLine = ''; /** * @var StreamInterface $stream * @phpstan-ignore-next-line */ - private $stream; + private StreamInterface $stream; /** * Overridden to return the position in the target encoding. diff --git a/src/SeekingLimitStream.php b/src/SeekingLimitStream.php index 9291afc..5ee89a0 100644 --- a/src/SeekingLimitStream.php +++ b/src/SeekingLimitStream.php @@ -15,34 +15,32 @@ * seeks back to the original position of the underlying stream after reading if * the attached stream supports seeking. * - * Although based on LimitStream, it's not inherited from it since $offset and - * $limit are set to private on LimitStream, and most other functions are re- - * implemented anyway. This also decouples the implementation from upstream + * Although copied form LimitStream, it's not inherited from it since $offset + * and $limit are set to private on LimitStream, and most other functions are + * re-implemented anyway. This also decouples the implementation from upstream * changes. - * - * @author Zaahid Bateson */ class SeekingLimitStream implements StreamInterface { use StreamDecoratorTrait; /** @var int Offset to start reading from */ - private $offset; + private int $offset; /** @var int Limit the number of bytes that can be read */ - private $limit; + private int $limit; /** * @var int Number of bytes written, and importantly, if non-zero, writes a * final $lineEnding on close (and so maintained instead of using * tell() directly) */ - private $position = 0; + private int $position = 0; /** * @var StreamInterface $stream */ - private $stream; + private StreamInterface $stream; /** * @param StreamInterface $stream Stream to wrap