Skip to content

Commit 5b26a69

Browse files
committed
Strongly-typed member variables
1 parent f8b2b28 commit 5b26a69

7 files changed

+32
-34
lines changed

src/Base64Stream.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ class Base64Stream implements StreamInterface
4747
/**
4848
* @var BufferStream buffered bytes
4949
*/
50-
private $buffer;
50+
private BufferStream $buffer;
5151

5252
/**
5353
* @var string remainder of write operation if the bytes didn't align to 3
5454
* bytes
5555
*/
56-
private $remainder = '';
56+
private string $remainder = '';
5757

5858
/**
5959
* @var int current number of read/written bytes (for tell())
6060
*/
61-
private $position = 0;
61+
private int $position = 0;
6262

6363
/**
6464
* @var StreamInterface $stream
6565
*/
66-
private $stream;
66+
private StreamInterface $stream;
6767

6868
public function __construct(StreamInterface $stream)
6969
{

src/CharsetStream.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,39 @@ class CharsetStream implements StreamInterface
2424
/**
2525
* @var MbWrapper the charset converter
2626
*/
27-
protected $converter = null;
27+
protected MbWrapper $converter;
2828

2929
/**
3030
* @var string charset of the source stream
3131
*/
32-
protected $streamCharset = 'ISO-8859-1';
32+
protected string $streamCharset = 'ISO-8859-1';
3333

3434
/**
3535
* @var string charset of strings passed in write operations, and returned
3636
* in read operations.
3737
*/
38-
protected $stringCharset = 'UTF-8';
38+
protected string $stringCharset = 'UTF-8';
3939

4040
/**
4141
* @var int current read/write position
4242
*/
43-
private $position = 0;
43+
private int $position = 0;
4444

4545
/**
4646
* @var int number of $stringCharset characters in $buffer
4747
*/
48-
private $bufferLength = 0;
48+
private int $bufferLength = 0;
4949

5050
/**
5151
* @var string a buffer of characters read in the original $streamCharset
5252
* encoding
5353
*/
54-
private $buffer = '';
54+
private string $buffer = '';
5555

5656
/**
5757
* @var StreamInterface $stream
5858
*/
59-
private $stream;
59+
private StreamInterface $stream;
6060

6161
/**
6262
* @param StreamInterface $stream Stream to decorate

src/ChunkSplitStream.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,32 @@ class ChunkSplitStream implements StreamInterface
2525
* final $lineEnding on close (and so maintained instead of using
2626
* tell() directly)
2727
*/
28-
private $position;
28+
private int $position;
2929

3030
/**
3131
* @var int The number of characters in a line before inserting $lineEnding.
3232
*/
33-
private $lineLength;
33+
private int $lineLength;
3434

3535
/**
3636
* @var string The line ending characters to insert.
3737
*/
38-
private $lineEnding;
38+
private string $lineEnding;
3939

4040
/**
4141
* @var int The strlen() of $lineEnding
4242
*/
43-
private $lineEndingLength;
43+
private int $lineEndingLength;
4444

4545
/**
4646
* @var StreamInterface $stream
4747
*/
48-
private $stream;
48+
private StreamInterface $stream;
4949

5050
public function __construct(StreamInterface $stream, int $lineLength = 76, string $lineEnding = "\r\n")
5151
{
5252
$this->stream = $stream;
53+
$this->position = 0;
5354
$this->lineLength = $lineLength;
5455
$this->lineEnding = $lineEnding;
5556
$this->lineEndingLength = \strlen($this->lineEnding);

src/NonClosingStream.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class NonClosingStream implements StreamInterface
4444
* @var ?StreamInterface $stream
4545
* @phpstan-ignore-next-line
4646
*/
47-
private $stream;
47+
private ?StreamInterface $stream;
4848

4949
/**
5050
* @inheritDoc
@@ -62,7 +62,6 @@ public function close() : void
6262
public function detach()
6363
{
6464
$this->stream = null; // @phpstan-ignore-line
65-
6665
return null;
6766
}
6867
}

src/PregReplaceFilterStream.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ class PregReplaceFilterStream implements StreamInterface
2727
/**
2828
* @var string The regex pattern
2929
*/
30-
private $pattern;
30+
private string $pattern;
3131

3232
/**
3333
* @var string The replacement
3434
*/
35-
private $replacement;
35+
private string $replacement;
3636

3737
/**
3838
* @var BufferStream Buffered stream of input from the underlying stream
3939
*/
40-
private $buffer;
40+
private BufferStream $buffer;
4141

4242
/**
4343
* @var StreamInterface $stream
4444
*/
45-
private $stream;
45+
private StreamInterface $stream;
4646

4747
public function __construct(StreamInterface $stream, string $pattern, string $replacement)
4848
{

src/QuotedPrintableStream.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ class QuotedPrintableStream implements StreamInterface
2323
/**
2424
* @var int current read/write position
2525
*/
26-
private $position = 0;
26+
private int $position = 0;
2727

2828
/**
2929
* @var string Last line of written text (used to maintain good line-breaks)
3030
*/
31-
private $lastLine = '';
31+
private string $lastLine = '';
3232

3333
/**
3434
* @var StreamInterface $stream
3535
* @phpstan-ignore-next-line
3636
*/
37-
private $stream;
37+
private StreamInterface $stream;
3838

3939
/**
4040
* Overridden to return the position in the target encoding.

src/SeekingLimitStream.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,32 @@
1515
* seeks back to the original position of the underlying stream after reading if
1616
* the attached stream supports seeking.
1717
*
18-
* Although based on LimitStream, it's not inherited from it since $offset and
19-
* $limit are set to private on LimitStream, and most other functions are re-
20-
* implemented anyway. This also decouples the implementation from upstream
18+
* Although copied form LimitStream, it's not inherited from it since $offset
19+
* and $limit are set to private on LimitStream, and most other functions are
20+
* re-implemented anyway. This also decouples the implementation from upstream
2121
* changes.
22-
*
23-
* @author Zaahid Bateson
2422
*/
2523
class SeekingLimitStream implements StreamInterface
2624
{
2725
use StreamDecoratorTrait;
2826

2927
/** @var int Offset to start reading from */
30-
private $offset;
28+
private int $offset;
3129

3230
/** @var int Limit the number of bytes that can be read */
33-
private $limit;
31+
private int $limit;
3432

3533
/**
3634
* @var int Number of bytes written, and importantly, if non-zero, writes a
3735
* final $lineEnding on close (and so maintained instead of using
3836
* tell() directly)
3937
*/
40-
private $position = 0;
38+
private int $position = 0;
4139

4240
/**
4341
* @var StreamInterface $stream
4442
*/
45-
private $stream;
43+
private StreamInterface $stream;
4644

4745
/**
4846
* @param StreamInterface $stream Stream to wrap

0 commit comments

Comments
 (0)