From b46726e666b5d2ad32959ae9492ee1034e798162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20M=C3=A4nnchen?= Date: Wed, 19 Apr 2023 20:51:03 +0100 Subject: [PATCH] Support PSR7 / HTTP Message v2 --- composer.json | 2 +- test/EndlessCycleStream.php | 17 +++++++---------- test/ResourceStream.php | 8 ++++---- test/ZipStreamTest.php | 4 ++-- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 31639ee..98c536a 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "vimeo/psalm": "^5.0" }, "suggest": { - "psr/http-message": "^1.0", + "psr/http-message": "^2.0", "guzzlehttp/psr7": "^2.4" }, "scripts": { diff --git a/test/EndlessCycleStream.php b/test/EndlessCycleStream.php index ca22cb1..4f1cf5c 100644 --- a/test/EndlessCycleStream.php +++ b/test/EndlessCycleStream.php @@ -33,12 +33,9 @@ public function detach() return; } - /** - * @return null - */ - public function getSize() + public function getSize(): ?int { - return; + return null; } public function tell(): int @@ -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: @@ -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'); } @@ -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); @@ -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 : []; } diff --git a/test/ResourceStream.php b/test/ResourceStream.php index 36111d6..8a41471 100644 --- a/test/ResourceStream.php +++ b/test/ResourceStream.php @@ -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(); @@ -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; @@ -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(); @@ -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(); diff --git a/test/ZipStreamTest.php b/test/ZipStreamTest.php index be7240d..153dda4 100644 --- a/test/ZipStreamTest.php +++ b/test/ZipStreamTest.php @@ -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'); }