Skip to content

psr/http-message 2.0 #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
],
"homepage": "http://violet.riimu.net",
"require": {
"php": ">=5.6.0",
"psr/http-message": "^1.0"
"php": "^7.2 || ^8.0",
"psr/http-message": "^1.1 || ^2.0"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions src/JsonStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __toString()
/**
* Frees the JSON encoder from memory and prevents further reading from the JSON stream.
*/
public function close()
public function close(): void
{
$this->encoder = null;
}
Expand All @@ -92,7 +92,7 @@ public function detach()
* Returns the total size of the JSON stream.
* @return null Always returns null as the total size cannot be determined
*/
public function getSize()
public function getSize(): ?int
{
return null;
}
Expand All @@ -101,7 +101,7 @@ public function getSize()
* Returns the current position of the cursor in the JSON stream.
* @return int Current position of the cursor
*/
public function tell()
public function tell(): int
{
$this->getEncoder();
return $this->cursor;
Expand All @@ -111,7 +111,7 @@ public function tell()
* Tells if there are no more bytes to read from the JSON stream.
* @return bool True if there are no more bytes to read, false if there are
*/
public function eof()
public function eof(): bool
{
return $this->buffer === null;
}
Expand All @@ -120,7 +120,7 @@ public function eof()
* Tells if the JSON stream is seekable or not.
* @return bool Always returns true as JSON streams as always seekable
*/
public function isSeekable()
public function isSeekable(): bool
{
return true;
}
Expand All @@ -140,7 +140,7 @@ public function isSeekable()
* @param int $whence Either SEEK_CUR or SEEK_SET to determine new cursor position
* @throws \RuntimeException If SEEK_END is used to determine the cursor position
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
$position = $this->calculatePosition($offset, $whence);

Expand All @@ -160,7 +160,7 @@ public function seek($offset, $whence = SEEK_SET)
* @return int The new cursor position
* @throws \RuntimeException If SEEK_END is used to determine the cursor position
*/
private function calculatePosition($offset, $whence)
private function calculatePosition(int $offset, int $whence): int
{
if ($whence === SEEK_CUR) {
return max(0, $this->cursor + (int) $offset);
Expand All @@ -177,7 +177,7 @@ private function calculatePosition($offset, $whence)
* Forwards the JSON stream reading cursor to the given position or to the end of stream.
* @param int $position The new position of the cursor
*/
private function forward($position)
private function forward(int $position): void
{
$encoder = $this->getEncoder();

Expand Down Expand Up @@ -209,7 +209,7 @@ private function forward($position)
* If the encoding has already been started, rewinding the encoder may not work,
* if the underlying value being encoded does not support rewinding.
*/
public function rewind()
public function rewind(): void
{
$this->seek(0);
}
Expand All @@ -218,7 +218,7 @@ public function rewind()
* Tells if the JSON stream is writable or not.
* @return bool Always returns false as JSON streams are never writable
*/
public function isWritable()
public function isWritable(): bool
{
return false;
}
Expand All @@ -233,7 +233,7 @@ public function isWritable()
* @return int The number of bytes written
* @throws \RuntimeException Always throws a runtime exception
*/
public function write($string)
public function write(string $string): int
{
throw new \RuntimeException('Cannot write to a JSON stream');
}
Expand All @@ -242,7 +242,7 @@ public function write($string)
* Tells if the JSON stream is readable or not.
* @return bool Always returns true as JSON streams are always readable
*/
public function isReadable()
public function isReadable(): bool
{
return true;
}
Expand All @@ -259,7 +259,7 @@ public function isReadable()
* @param int $length The number of bytes to return
* @return string The bytes read from the JSON stream
*/
public function read($length)
public function read(int $length): string
{
if ($this->eof()) {
return '';
Expand Down Expand Up @@ -290,7 +290,7 @@ public function read($length)
* Returns the remaining bytes from the JSON stream.
* @return string The remaining bytes from JSON stream
*/
public function getContents()
public function getContents(): string
{
if ($this->eof()) {
return '';
Expand Down Expand Up @@ -320,7 +320,7 @@ public function getContents()
* @param string|null $key The key of the value to return
* @return array|mixed|null The meta data array, a specific value or null if not defined
*/
public function getMetadata($key = null)
public function getMetadata(?string $key = null)
{
$meta = [
'timed_out' => false,
Expand Down