diff --git a/src/Body/FormPayload.php b/src/Body/FormPayload.php index 80d0616..913ebfa 100644 --- a/src/Body/FormPayload.php +++ b/src/Body/FormPayload.php @@ -9,17 +9,11 @@ final class FormPayload extends Map implements PayloadInterface { - /** - * Get the header content type value. - */ public function contentType(): ?string { return 'application/x-www-form-urlencoded'; } - /** - * Get the string representation of the payload. - */ public function __toString() { return \http_build_query($this->all()); diff --git a/src/Body/JsonPayload.php b/src/Body/JsonPayload.php index 877e2ee..7c80674 100644 --- a/src/Body/JsonPayload.php +++ b/src/Body/JsonPayload.php @@ -21,17 +21,11 @@ public function __construct(array $parameters = [], int $flags = 0) $this->flags = $flags; } - /** - * Get the header content type value. - */ public function contentType(): ?string { return 'application/json'; } - /** - * Get the string representation of the payload. - */ public function __toString() { return \json_encode($this->all(), $this->flags) ?: ''; diff --git a/src/Body/MultipartPayload.php b/src/Body/MultipartPayload.php index 738e2a5..4858905 100644 --- a/src/Body/MultipartPayload.php +++ b/src/Body/MultipartPayload.php @@ -17,13 +17,6 @@ final class MultipartPayload extends Map implements PayloadInterface */ private $boundary; - /** - * Create new multipart payload instance. - * - * @param array $parameters - * @param null|string $boundary - * @return void - */ public function __construct(array $parameters = [], ?string $boundary = null) { parent::__construct($parameters); @@ -31,9 +24,6 @@ public function __construct(array $parameters = [], ?string $boundary = null) $this->boundary = $boundary ?: \bin2hex(\random_bytes(20)); } - /** - * Get the header content type value. - */ public function contentType(): ?string { return 'multipart/form-data; boundary='.$this->boundary; @@ -94,9 +84,6 @@ private function part(string $name, $value): string return $str; } - /** - * Get the string representation of the payload. - */ public function __toString() { $str = ''; diff --git a/src/Body/RawPayload.php b/src/Body/RawPayload.php index 3c66185..14a5a1d 100644 --- a/src/Body/RawPayload.php +++ b/src/Body/RawPayload.php @@ -19,9 +19,6 @@ public function __construct(string $payload = '') $this->payload = $payload; } - /** - * Get the header content type value. - */ public function contentType(): ?string { return null; @@ -114,9 +111,6 @@ public function isEmpty(): bool return $this->payload === ''; } - /** - * Get the string representation of the payload. - */ public function __toString() { return $this->payload; diff --git a/src/ConnectorConfigurator.php b/src/ConnectorConfigurator.php index 5ebdeae..2bde60d 100644 --- a/src/ConnectorConfigurator.php +++ b/src/ConnectorConfigurator.php @@ -19,7 +19,7 @@ class ConnectorConfigurator { /** - * @var \Closure[] + * @var array<\Closure(T): void> */ private $handlers = []; @@ -64,7 +64,6 @@ final public function middleware(callable $middleware, string $name = '') protected function register(\Closure $handler) { $clone = clone $this; - $clone->handlers[] = $handler; return $clone; diff --git a/src/Decoder/ChainDecoder.php b/src/Decoder/ChainDecoder.php index 6a4775b..97c729d 100644 --- a/src/Decoder/ChainDecoder.php +++ b/src/Decoder/ChainDecoder.php @@ -26,6 +26,10 @@ public function __construct(iterable $decoders) public function decode(ResponseInterface $response): iterable { foreach ($this->decoders as $decoder) { + if (! $decoder instanceof DecoderInterface) { + throw new \InvalidArgumentException(sprintf('Decoder must implement %s. %s given', DecoderInterface::class, \get_debug_type($decoder))); + } + try { yield from $decoder->decode($response); } catch (NotDecodableException $e) { diff --git a/src/Middleware.php b/src/Middleware.php index ae5a4ff..26501c1 100644 --- a/src/Middleware.php +++ b/src/Middleware.php @@ -14,6 +14,9 @@ final class Middleware implements \IteratorAggregate, \Countable */ private $middleware = []; + /** + * @param array $middleware + */ public function __construct(array $middleware = []) { foreach ($middleware as $name => $value) { diff --git a/src/Middleware/Interceptor.php b/src/Middleware/Interceptor.php index e0af739..fd9115b 100644 --- a/src/Middleware/Interceptor.php +++ b/src/Middleware/Interceptor.php @@ -12,6 +12,8 @@ final class Interceptor { /** * Add a request interceptor. + * + * @param \Closure(RequestInterface): RequestInterface $callback */ public static function request(Closure $callback): Closure { @@ -22,6 +24,8 @@ public static function request(Closure $callback): Closure /** * Add a response interceptor. + * + * @param \Closure(ResponseInterface): ResponseInterface $callback */ public static function response(Closure $callback): Closure { diff --git a/src/Retry/RetryCallback.php b/src/Retry/RetryCallback.php index 94765dc..4002777 100644 --- a/src/Retry/RetryCallback.php +++ b/src/Retry/RetryCallback.php @@ -13,15 +13,19 @@ final class RetryCallback implements RetryStrategyInterface { /** - * @var \Closure + * @var \Closure(RequestInterface, ResponseInterface): bool */ private $when; /** - * @var \Closure + * @var \Closure(RetryContext): int */ private $delay; + /** + * @param \Closure(RequestInterface, ResponseInterface): bool $when + * @param \Closure(RetryContext): int $delay + */ public function __construct(Closure $when, Closure $delay) { $this->when = $when; diff --git a/src/Traits/HasClient.php b/src/Traits/HasClient.php index 1f51cba..df641bd 100644 --- a/src/Traits/HasClient.php +++ b/src/Traits/HasClient.php @@ -24,7 +24,6 @@ trait HasClient public function withClient(ClientInterface $client) { $clone = clone $this; - $clone->client = $client; return $clone; diff --git a/src/Traits/HasMiddleware.php b/src/Traits/HasMiddleware.php index d372997..1e35def 100644 --- a/src/Traits/HasMiddleware.php +++ b/src/Traits/HasMiddleware.php @@ -5,6 +5,8 @@ namespace Fansipan\Traits; use Fansipan\Middleware; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; trait HasMiddleware { @@ -29,6 +31,8 @@ public function middleware(): Middleware /** * Get default middleware. + * + * @return array */ protected function defaultMiddleware(): array {