Skip to content

Commit

Permalink
Strongly-typed member variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zbateson committed Mar 27, 2024
1 parent f8b2b28 commit 5b26a69
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/Base64Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 7 additions & 7 deletions src/CharsetStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/ChunkSplitStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/NonClosingStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class NonClosingStream implements StreamInterface
* @var ?StreamInterface $stream
* @phpstan-ignore-next-line
*/
private $stream;
private ?StreamInterface $stream;

/**
* @inheritDoc
Expand All @@ -62,7 +62,6 @@ public function close() : void
public function detach()
{
$this->stream = null; // @phpstan-ignore-line

return null;
}
}
8 changes: 4 additions & 4 deletions src/PregReplaceFilterStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions src/QuotedPrintableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 7 additions & 9 deletions src/SeekingLimitStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b26a69

Please sign in to comment.