Skip to content

Commit

Permalink
Support PSR7 / HTTP Message v2
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Apr 19, 2023
1 parent 86b3487 commit b46726e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"vimeo/psalm": "^5.0"
},
"suggest": {
"psr/http-message": "^1.0",
"psr/http-message": "^2.0",
"guzzlehttp/psr7": "^2.4"
},
"scripts": {
Expand Down
17 changes: 7 additions & 10 deletions test/EndlessCycleStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ public function detach()
return;
}

/**
* @return null
*/
public function getSize()
public function getSize(): ?int
{
return;
return null;
}

public function tell(): int
Expand All @@ -51,12 +48,12 @@ public function eof(): bool
return false;
}

public function isSeekable()
public function isSeekable(): bool
{
return true;
}

public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
switch($whence) {
case SEEK_SET:
Expand All @@ -81,7 +78,7 @@ public function isWritable(): bool
return false;
}

public function write($string): int
public function write(string $string): int
{
throw new RuntimeException('Not writeable');
}
Expand All @@ -91,7 +88,7 @@ public function isReadable(): bool
return true;
}

public function read($length): string
public function read(int $length): string
{
$this->offset += $length;
return substr(str_repeat($this->toRepeat, (int) ceil($length / strlen($this->toRepeat))), 0, $length);
Expand All @@ -102,7 +99,7 @@ public function getContents(): string
throw new RuntimeException('Infinite Stream!');
}

public function getMetadata($key = null): array|null
public function getMetadata(?string $key = null): array|null
{
return $key !== null ? null : [];
}
Expand Down
8 changes: 4 additions & 4 deletions test/ResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function detach()
return $result;
}

public function seek($offset, $whence = SEEK_SET): void
public function seek(int $offset, int $whence = SEEK_SET): void
{
if (!$this->isSeekable()) {
throw new RuntimeException();
Expand All @@ -62,7 +62,7 @@ public function isSeekable(): bool
return (bool)$this->getMetadata('seekable');
}

public function getMetadata($key = null)
public function getMetadata(?string $key = null)
{
$metadata = stream_get_meta_data($this->stream);
return $key !== null ? @$metadata[$key] : $metadata;
Expand Down Expand Up @@ -95,7 +95,7 @@ public function rewind(): void
$this->seek(0);
}

public function write($string): int
public function write(string $string): int
{
if (!$this->isWritable()) {
throw new RuntimeException();
Expand All @@ -119,7 +119,7 @@ public function isWritable(): bool
return preg_match('/[waxc+]/', $mode) === 1;
}

public function read($length): string
public function read(int $length): string
{
if (!$this->isReadable()) {
throw new RuntimeException();
Expand Down
4 changes: 2 additions & 2 deletions test/ZipStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,12 @@ public function testAddFileFromStreamUnseekableInputWithZeroHeader(): void
);

$streamUnseekable = StreamWrapper::getResource(new class ('test') extends EndlessCycleStream {
public function isSeekable()
public function isSeekable(): bool
{
return false;
}

public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
throw new RuntimeException('Not seekable');
}
Expand Down

0 comments on commit b46726e

Please sign in to comment.