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 pending PHPStan errors in PR #233 #234

Closed
wants to merge 3 commits into from
Closed
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
32 changes: 0 additions & 32 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ parameters:
count: 1
path: src/PluginClient.php

-
message: "#^Method Http\\\\Client\\\\Common\\\\EmulatedHttpClient\\:\\:sendRequest\\(\\) should return Psr\\\\Http\\\\Message\\\\ResponseInterface but returns mixed\\.$#"
count: 1
path: src/EmulatedHttpClient.php

# we still support the obsolete RequestFactory for BC but do not require the package anymore
-
message: "#^Call to method createRequest\\(\\) on an unknown class Http\\\\Message\\\\RequestFactory\\.$#"
Expand All @@ -51,30 +46,3 @@ parameters:
message: "#^Property Http\\\\Client\\\\Common\\\\HttpMethodsClient\\:\\:\\$requestFactory has unknown class Http\\\\Message\\\\RequestFactory as its type\\.$#"
count: 1
path: src/HttpMethodsClient.php

-
message: "#^Anonymous function should return Psr\\\\Http\\\\Message\\\\ResponseInterface but returns mixed\\.$#"
count: 1
path: src/Plugin/RedirectPlugin.php

# phpstan is confused by the optional dependencies. we check for existence first
-
message: "#^Method Http\\\\Client\\\\Common\\\\Plugin\\\\RedirectPlugin::guessStreamFactory\\(\\) should return Psr\\\\Http\\\\Message\\\\StreamFactoryInterface\\|null but returns Nyholm\\\\Psr7\\\\Factory\\\\Psr17Factory\\.$#"
count: 1
path: src/Plugin/RedirectPlugin.php

# phpstan is confused by the optional dependencies. we check for existence first
-
message: "#^Call to static method streamFor\\(\\) on an unknown class GuzzleHttp\\\\Psr7\\\\Utils\\.$#"
count: 1
path: src/Plugin/RedirectPlugin.php

-
message: "#^Method Http\\\\Client\\\\Common\\\\Plugin\\\\RetryPlugin\\:\\:retry\\(\\) should return Psr\\\\Http\\\\Message\\\\ResponseInterface but returns mixed\\.$#"
count: 1
path: src/Plugin/RetryPlugin.php

-
message: "#^Method Http\\\\Client\\\\Common\\\\PluginClient\\:\\:sendRequest\\(\\) should return Psr\\\\Http\\\\Message\\\\ResponseInterface but returns mixed\\.$#"
count: 2
path: src/PluginClient.php
14 changes: 8 additions & 6 deletions src/Deferred.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

/**
* A deferred allow to return a promise which has not been resolved yet.
*
* @implements Promise<ResponseInterface>
*/
final class Deferred implements Promise
{
Expand Down Expand Up @@ -52,7 +54,9 @@ public function __construct(callable $waitCallback)
}

/**
* {@inheritdoc}
* @param callable(ResponseInterface): ResponseInterface|null $onFulfilled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be necessary with the @implements in the class docblock, it should come automatically from the covariant in the interface.

* @param callable(\Throwable): ResponseInterface|null $onRejected
* @return Promise<ResponseInterface>
*/
public function then(callable $onFulfilled = null, callable $onRejected = null): Promise
{
Expand Down Expand Up @@ -86,16 +90,14 @@ public function then(callable $onFulfilled = null, callable $onRejected = null):
return $deferred;
}

/**
* {@inheritdoc}
*/
public function getState(): string
{
return $this->state;
}

/**
* Resolve this deferred with a Response.
* @param ResponseInterface $response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't add phpdoc when it does not add information

Suggested change
* @param ResponseInterface $response

*/
public function resolve(ResponseInterface $response): void
{
Expand Down Expand Up @@ -129,8 +131,8 @@ public function reject(ClientExceptionInterface $exception): void
}

/**
* {@inheritdoc}
*/
* {@inheritDoc}
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't do inheritdoc when there is nothing else. if there is no docblock, most tools take the docblock of the parent/interface

public function wait($unwrap = true)
{
if (Promise::PENDING === $this->state) {
Expand Down
5 changes: 3 additions & 2 deletions src/HttpAsyncClientDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Http\Client\Common;

use Http\Client\HttpAsyncClient;
use Http\Promise\Promise;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\RequestInterface;

/**
Expand All @@ -20,9 +22,8 @@ trait HttpAsyncClientDecorator
protected $httpAsyncClient;

/**
* {@inheritdoc}
*
* @see HttpAsyncClient::sendAsyncRequest
* @return Promise<ResponseInterface>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to fix this in the HttpAsyncClient instead. then it will be inferred for all the various implementations here:

https://github.com/php-http/httplug/blob/625ad742c360c8ac580fcc647a1541d29e257f67/src/HttpAsyncClient.php#L20

*/
public function sendAsyncRequest(RequestInterface $request)
{
Expand Down
5 changes: 1 addition & 4 deletions src/HttpAsyncClientEmulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
trait HttpAsyncClientEmulator
{
/**
* {@inheritdoc}
*
* @see HttpClient::sendRequest
*/
abstract public function sendRequest(RequestInterface $request): ResponseInterface;

/**
* {@inheritdoc}
*
* @see HttpAsyncClient::sendAsyncRequest
* @return \Http\Promise\Promise<ResponseInterface|\Throwable>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in interface instead

*/
public function sendAsyncRequest(RequestInterface $request)
{
Expand Down
2 changes: 0 additions & 2 deletions src/HttpClientDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ trait HttpClientDecorator
protected $httpClient;

/**
* {@inheritdoc}
*
* @see ClientInterface::sendRequest
*/
public function sendRequest(RequestInterface $request): ResponseInterface
Expand Down
4 changes: 0 additions & 4 deletions src/HttpClientEmulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
trait HttpClientEmulator
{
/**
* {@inheritdoc}
*
* @see HttpClient::sendRequest
*/
public function sendRequest(RequestInterface $request): ResponseInterface
Expand All @@ -27,8 +25,6 @@ public function sendRequest(RequestInterface $request): ResponseInterface
}

/**
* {@inheritdoc}
*
* @see HttpAsyncClient::sendAsyncRequest
*/
abstract public function sendAsyncRequest(RequestInterface $request);
Expand Down
6 changes: 2 additions & 4 deletions src/HttpClientPool/HttpClientPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Http\Client\Common\Exception\HttpClientNotFoundException;
use Http\Client\Common\HttpClientPool as HttpClientPoolInterface;
use Http\Client\HttpAsyncClient;
use Http\Promise\Promise;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -53,16 +54,13 @@ public function addHttpClient($client): void
abstract protected function chooseHttpClient(): HttpClientPoolItem;

/**
* {@inheritdoc}
* @return Promise<ResponseInterface>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed when HttpAsyncClient defines the return type

*/
public function sendAsyncRequest(RequestInterface $request)
{
return $this->chooseHttpClient()->sendAsyncRequest($request);
}

/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
return $this->chooseHttpClient()->sendRequest($request);
Expand Down
6 changes: 2 additions & 4 deletions src/HttpClientPool/HttpClientPoolItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Http\Client\Exception;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use Http\Promise\Promise;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -69,9 +70,6 @@ public function __construct($client, int $reenableAfter = null)
$this->reenableAfter = $reenableAfter;
}

/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
if ($this->isDisabled()) {
Expand All @@ -93,7 +91,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
}

/**
* {@inheritdoc}
* @return Promise<ResponseInterface>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed when HttpAsyncClient defines the return type

*/
public function sendAsyncRequest(RequestInterface $request)
{
Expand Down
3 changes: 0 additions & 3 deletions src/HttpClientPool/LeastUsedClientPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
final class LeastUsedClientPool extends HttpClientPool
{
/**
* {@inheritdoc}
*/
protected function chooseHttpClient(): HttpClientPoolItem
{
$clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) {
Expand Down
3 changes: 0 additions & 3 deletions src/HttpClientPool/RandomClientPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*/
final class RandomClientPool extends HttpClientPool
{
/**
* {@inheritdoc}
*/
protected function chooseHttpClient(): HttpClientPoolItem
{
$clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) {
Expand Down
3 changes: 0 additions & 3 deletions src/HttpClientPool/RoundRobinClientPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*/
final class RoundRobinClientPool extends HttpClientPool
{
/**
* {@inheritdoc}
*/
protected function chooseHttpClient(): HttpClientPoolItem
{
$last = current($this->clientPool);
Expand Down
8 changes: 2 additions & 6 deletions src/HttpClientRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
use Http\Client\Common\Exception\HttpClientNoMatchException;
use Http\Client\HttpAsyncClient;
use Http\Message\RequestMatcher;
use Http\Promise\Promise;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* {@inheritdoc}
*
* @author Joel Wurtz <joel.wurtz@gmail.com>
*/
final class HttpClientRouter implements HttpClientRouterInterface
Expand All @@ -23,16 +22,13 @@ final class HttpClientRouter implements HttpClientRouterInterface
*/
private $clients = [];

/**
* {@inheritdoc}
*/
public function sendRequest(RequestInterface $request): ResponseInterface
{
return $this->chooseHttpClient($request)->sendRequest($request);
}

/**
* {@inheritdoc}
* @return Promise<ResponseInterface>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed when HttpAsyncClient defines the return type

*/
public function sendAsyncRequest(RequestInterface $request)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Http\Client\Common;

use Http\Promise\Promise;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\RequestInterface;

/**
Expand All @@ -24,10 +25,10 @@ interface Plugin
*
* @see http://docs.php-http.org/en/latest/plugins/build-your-own.html
*
* @param callable(RequestInterface): Promise $next Next middleware in the chain, the request is passed as the first argument
* @param callable(RequestInterface): Promise $first First middleware in the chain, used to to restart a request
* @param callable(RequestInterface): Promise<ResponseInterface> $next Next middleware in the chain, the request is passed as the first argument
* @param callable(RequestInterface): Promise<ResponseInterface> $first First middleware in the chain, used to to restart a request
*
* @return Promise Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient)
* @return Promise<ResponseInterface> Resolves a PSR-7 Response or fails with an Http\Client\Exception (The same as HttpAsyncClient)
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise;
}
3 changes: 0 additions & 3 deletions src/Plugin/AddHostPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public function __construct(UriInterface $host, array $config = [])
$this->replace = $options['replace'];
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
if ($this->replace || '' === $request->getUri()->getHost()) {
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/AuthenticationPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public function __construct(Authentication $authentication)
$this->authentication = $authentication;
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$request = $this->authentication->authenticate($request);
Expand Down
5 changes: 1 addition & 4 deletions src/Plugin/BaseUriPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class BaseUriPlugin implements Plugin
/**
* @var AddPathPlugin|null
*/
private $addPathPlugin = null;
private $addPathPlugin;

/**
* @param UriInterface $uri Has to contain a host name and can have a path
Expand All @@ -39,9 +39,6 @@ public function __construct(UriInterface $uri, array $hostConfig = [])
}
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$addHostNext = function (RequestInterface $request) use ($next, $first) {
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/ContentLengthPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
final class ContentLengthPlugin implements Plugin
{
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
if (!$request->hasHeader('Content-Length')) {
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/ContentTypePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ public function __construct(array $config = [])
$this->sizeLimit = $options['size_limit'];
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
if (!$request->hasHeader('Content-Type')) {
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public function __construct(CookieJar $cookieJar)
$this->cookieJar = $cookieJar;
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$cookies = [];
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/DecoderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ public function __construct(array $config = [])
$this->useContentEncoding = $options['use_content_encoding'];
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$encodings = extension_loaded('zlib') ? ['gzip', 'deflate'] : ['identity'];
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/ErrorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ public function __construct(array $config = [])
$this->onlyServerException = $options['only_server_exception'];
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$promise = $next($request);
Expand Down
3 changes: 0 additions & 3 deletions src/Plugin/HeaderAppendPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public function __construct(array $headers)
$this->headers = $headers;
}

/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
foreach ($this->headers as $header => $headerValue) {
Expand Down
Loading