Skip to content
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

fix: Typehint the Stream class and fix deprecated interface HttpClient #70

Open
wants to merge 2 commits into
base: 2.x
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 2.1.2

* Fixed the type hinting of Stream class in order to make it compatible with StreamInterface
* Replaced the deprecated interface HttpClient

## 2.1.1

* Fixed constructor to work nicely with version 1 style arguments (e.g. HttplugBundle)
Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Http\Client\Socket;

use Http\Client\HttpClient;
use Http\Client\Socket\Exception\ConnectionException;
use Http\Client\Socket\Exception\InvalidRequestException;
use Http\Client\Socket\Exception\SSLConnectionException;
use Http\Client\Socket\Exception\TimeoutException;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
Expand All @@ -20,7 +20,7 @@
*
* @author Joel Wurtz <[email protected]>
*/
class Client implements HttpClient
class Client implements ClientInterface
{
use RequestWriter;
use ResponseReader;
Expand Down
26 changes: 13 additions & 13 deletions src/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(RequestInterface $request, $socket, ?int $size = nul
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
try {
return $this->getContents();
Expand All @@ -76,7 +76,7 @@ public function __toString()
/**
* {@inheritdoc}
*/
public function close()
public function close(): void
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
Expand Down Expand Up @@ -104,15 +104,15 @@ public function detach()
*
* @return int<0, max>|null
*/
public function getSize()
public function getSize(): ?int
{
return $this->size;
}

/**
* {@inheritdoc}
*/
public function tell()
public function tell(): int
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
Expand All @@ -128,7 +128,7 @@ public function tell()
/**
* {@inheritdoc}
*/
public function eof()
public function eof(): bool
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
Expand All @@ -140,7 +140,7 @@ public function eof()
/**
* {@inheritdoc}
*/
public function isSeekable()
public function isSeekable(): bool
{
return false;
}
Expand All @@ -150,7 +150,7 @@ public function isSeekable()
*
* @return void
*/
public function seek($offset, $whence = SEEK_SET)
public function seek($offset, $whence = SEEK_SET): void
{
throw new StreamException('This stream is not seekable');
}
Expand All @@ -160,31 +160,31 @@ public function seek($offset, $whence = SEEK_SET)
*
* @return void
*/
public function rewind()
public function rewind(): void
{
throw new StreamException('This stream is not seekable');
}

/**
* {@inheritdoc}
*/
public function isWritable()
public function isWritable(): bool
{
return false;
}

/**
* {@inheritdoc}
*/
public function write($string)
public function write($string): int
{
throw new StreamException('This stream is not writable');
}

/**
* {@inheritdoc}
*/
public function isReadable()
public function isReadable(): bool
{
return true;
}
Expand All @@ -194,7 +194,7 @@ public function isReadable()
*
* @param int<0, max> $length
*/
public function read($length)
public function read($length): string
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
Expand Down Expand Up @@ -235,7 +235,7 @@ public function read($length)
/**
* {@inheritdoc}
*/
public function getContents()
public function getContents(): string
{
if ($this->isDetached || null === $this->socket) {
throw new StreamException('Stream is detached');
Expand Down