Skip to content

Commit

Permalink
Merge pull request #121 from Xerkus/hotfix/psr-message
Browse files Browse the repository at this point in the history
Expand compatibility to allow `psr/http-message:^2`
  • Loading branch information
Ocramius authored Aug 23, 2023
2 parents 17e6a6e + 1f2f91d commit bee6718
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"psr/container": "^1.1.2 || ^2.0.2",
"psr/event-dispatcher": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"psr/http-message-implementation": "^1.0",
"psr/http-message-implementation": "^1.0 || ^2.0",
"psr/http-server-handler": "^1.0.2",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^5.0 || ^6.0.19",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

10 changes: 10 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@
</PossiblyUnusedReturnValue>
</file>
<file src="src/SwooleStream.php">
<PossiblyNullOperand>
<code>$size</code>
<code>$size</code>
</PossiblyNullOperand>
<PossiblyNullPropertyAssignmentValue>
<code>$size</code>
<code><![CDATA[$this->index + $length >= $size
? $size
: $this->index + $length]]></code>
</PossiblyNullPropertyAssignmentValue>
<PossiblyUnusedReturnValue>
<code>int</code>
</PossiblyUnusedReturnValue>
Expand Down
46 changes: 13 additions & 33 deletions src/SwooleStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ public function __construct(
) {
}

/**
* @return string
*/
public function getContents()
public function getContents(): string
{
// If we're at the end of the string, return an empty string.
if ($this->eof()) {
Expand Down Expand Up @@ -87,10 +84,7 @@ public function __toString(): string
return (string) $this->body;
}

/**
* @return int
*/
public function getSize()
public function getSize(): ?int
{
if (null === $this->bodySize) {
if ($this->body === null) {
Expand All @@ -102,35 +96,25 @@ public function getSize()
return $this->bodySize;
}

/**
* @return int
*/
public function tell()
public function tell(): int
{
return $this->index;
}

/**
* @return bool
*/
public function eof()
public function eof(): bool
{
return $this->index >= $this->getSize();
}

/**
* @return bool Always returns true.
*/
public function isReadable()
public function isReadable(): bool
{
return true;
}

/**
* @param int $length
* @return string
*/
public function read($length)
public function read(int $length): string
{
if ($this->body === null) {
$this->initRawContent();
Expand All @@ -149,17 +133,15 @@ public function read($length)
/**
* @return bool Always returns true.
*/
public function isSeekable()
public function isSeekable(): bool
{
return true;
}

/**
* @param int $offset
* @param int $whence
* @psalm-return void
*/
public function seek($offset, $whence = SEEK_SET)
public function seek(int $offset, int $whence = SEEK_SET): void
{
$size = $this->getSize();
switch ($whence) {
Expand Down Expand Up @@ -200,26 +182,24 @@ public function seek($offset, $whence = SEEK_SET)
/**
* @psalm-return void
*/
public function rewind()
public function rewind(): void
{
$this->index = 0;
}

/**
* @return bool Always returns false.
*/
public function isWritable()
public function isWritable(): bool
{
return false;
}

// phpcs:disable Squiz.Commenting.FunctionComment.InvalidNoReturn
/**
* @param string $string
* @return int
* @throws RuntimeException Always throws, as not writable.
*/
public function write($string)
public function write(string $string): int
{
throw new RuntimeException('Stream is not writable');
}
Expand All @@ -229,7 +209,7 @@ public function write($string)
* @param string $key
* @return null|array
*/
public function getMetadata($key = null)
public function getMetadata($key = null): ?array
{
return $key ? null : [];
}
Expand All @@ -239,7 +219,7 @@ public function detach(): SwooleHttpRequest
return $this->request;
}

public function close()
public function close(): void
{
}

Expand Down

0 comments on commit bee6718

Please sign in to comment.