Skip to content

Commit

Permalink
Merge pull request #15 from phpfui/PSRFixes
Browse files Browse the repository at this point in the history
Update to new Psr\Http\Message\StreamInterface spec
  • Loading branch information
zbateson committed Apr 19, 2023
2 parents 0b988df + bf761ce commit 712b9e7
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.1, 8.0, 7.4, 7.3, 7.2, 7.1]
php: [8.2, 8.1, 8.0, 7.4, 7.3, 7.2]
stability: [prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -22,7 +22,7 @@ composer require zbateson/stream-decorators

## Requirements

StreamDecorators requires PHP 7.1 or newer. Tested on PHP 7.1, 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2.
StreamDecorators requires PHP 7.2 or newer. Tested on PHP 7.2, 7.3, 7.4, 8.0, 8.1 and 8.2.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -9,7 +9,7 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=7.2",
"guzzlehttp/psr7": "^1.9 | ^2.0",
"zbateson/mb-wrapper": "^1.0.0"
},
Expand Down
11 changes: 2 additions & 9 deletions src/Base64Stream.php
Expand Up @@ -92,13 +92,9 @@ public function getSize() : ?int
/**
* Not implemented (yet).
*
* Seek position can be calculated.
*
* @param int $offset
* @param int $whence
* @throws RuntimeException
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET) : void
{
throw new RuntimeException('Cannot seek a Base64Stream');
}
Expand Down Expand Up @@ -144,11 +140,8 @@ private function fillBuffer(int $length) : void
*
* Note that reading and writing to the same stream may result in wrongly
* encoded data and is not supported.
*
* @param int $length
* @return string
*/
public function read($length)
public function read(int $length) : string
{
// let Guzzle decide what to do.
if ($length <= 0 || $this->eof()) {
Expand Down
9 changes: 2 additions & 7 deletions src/CharsetStream.php
Expand Up @@ -93,11 +93,9 @@ public function getSize() : ?int
/**
* Not supported.
*
* @param int $offset
* @param int $whence
* @throws RuntimeException
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET) : void
{
throw new RuntimeException('Cannot seek a CharsetStream');
}
Expand Down Expand Up @@ -142,11 +140,8 @@ public function eof() : bool
/**
* Reads up to $length decoded chars from the underlying stream and returns
* them after converting to the target string charset.
*
* @param int $length
* @return string
*/
public function read($length)
public function read(int $length) : string
{
// let Guzzle decide what to do.
if ($length <= 0 || $this->eof()) {
Expand Down
9 changes: 2 additions & 7 deletions src/PregReplaceFilterStream.php
Expand Up @@ -63,11 +63,9 @@ public function eof() : bool
/**
* Not supported by PregReplaceFilterStream
*
* @param int $offset
* @param int $whence
* @throws RuntimeException
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET) : void
{
throw new RuntimeException('Cannot seek a PregReplaceFilterStream');
}
Expand Down Expand Up @@ -99,11 +97,8 @@ private function fillBuffer(int $length) : void
/**
* Reads from the underlying stream, filters it and returns up to $length
* bytes.
*
* @param int $length
* @return string
*/
public function read($length)
public function read(int $length) : string
{
$this->fillBuffer($length);
return $this->buffer->read($length);
Expand Down
6 changes: 1 addition & 5 deletions src/QuotedPrintableStream.php
Expand Up @@ -57,11 +57,9 @@ public function getSize() : ?int
/**
* Not supported.
*
* @param int $offset
* @param int $whence
* @throws RuntimeException
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET) : void
{
throw new RuntimeException('Cannot seek a QuotedPrintableStream');
}
Expand Down Expand Up @@ -138,8 +136,6 @@ private function readRawDecodeAndAppend(int $length, string &$str) : int
/**
* Reads up to $length decoded bytes from the underlying quoted-printable
* encoded stream and returns them.
*
* @param int $length
*/
public function read($length) : string
{
Expand Down
10 changes: 2 additions & 8 deletions src/SeekingLimitStream.php
Expand Up @@ -119,11 +119,8 @@ private function doSeek(int $pos) : void
* For SeekingLimitStream, no actual seek is performed on the underlying
* wrapped stream. Instead, an internal pointer is set, and the stream is
* 'seeked' on read operations
*
* @param int $offset
* @param int $whence
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET) : void
{
$pos = $offset;
switch ($whence) {
Expand Down Expand Up @@ -176,11 +173,8 @@ public function seekAndRead(int $length) : string
* Reads from the underlying stream after seeking to the position within the
* bounds set for this limited stream. After reading, the wrapped stream is
* 'seeked' back to its position prior to the call to read().
*
* @param int $length
* @return string
*/
public function read($length)
public function read(int $length) : string
{
$pos = $this->stream->tell();
$ret = $this->seekAndRead($length);
Expand Down
6 changes: 1 addition & 5 deletions src/UUStream.php
Expand Up @@ -88,11 +88,9 @@ public function getSize() : ?int
/**
* Not supported.
*
* @param int $offset
* @param int $whence
* @throws RuntimeException
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET) : void
{
throw new RuntimeException('Cannot seek a UUStream');
}
Expand Down Expand Up @@ -173,8 +171,6 @@ public function eof() : bool

/**
* Attempts to read $length bytes after decoding them, and returns them.
*
* @param int $length
*/
public function read($length) : string
{
Expand Down

0 comments on commit 712b9e7

Please sign in to comment.