From 054994cdb5cb5f8d5bac286cb6d35019be06091c Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Wed, 13 Oct 2021 09:20:36 -0500 Subject: [PATCH] Fix issues caught by static analysis tests. --- src/Api/Attachment.php | 8 +++----- src/Api/HttpApi.php | 1 + src/Assert.php | 3 +++ src/HttpClient/RequestBuilder.php | 3 +-- src/Hydrator/ModelHydrator.php | 1 + src/Hydrator/NoopHydrator.php | 1 + src/Message/Exceptions/LimitExceeded.php | 2 +- src/Message/Exceptions/TooManyRecipients.php | 4 ++-- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Api/Attachment.php b/src/Api/Attachment.php index bedee5eb..5bc8ec1a 100644 --- a/src/Api/Attachment.php +++ b/src/Api/Attachment.php @@ -12,11 +12,9 @@ namespace Mailgun\Api; use Mailgun\Assert; -use Mailgun\Exception\{ - HttpClientException, - HttpServerException, - UnknownErrorException -}; +use Mailgun\Exception\HttpClientException; +use Mailgun\Exception\HttpServerException; +use Mailgun\Exception\UnknownErrorException; use Psr\Http\Message\ResponseInterface; /** diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index 145f7e4f..9b489579 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -82,6 +82,7 @@ protected function hydrateResponse(ResponseInterface $response, string $class) * Throw the correct exception for this error. * * @throws HttpClientException|HttpServerException|UnknownErrorException + * * @return never */ protected function handleErrors(ResponseInterface $response): void diff --git a/src/Assert.php b/src/Assert.php index 984fa28b..c37c0a37 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -21,7 +21,10 @@ final class Assert extends \Webmozart\Assert\Assert { /** + * @psalm-pure + * * @throws InvalidArgumentException + * * @return never */ protected static function reportInvalidArgument($message): void diff --git a/src/HttpClient/RequestBuilder.php b/src/HttpClient/RequestBuilder.php index d180ff01..924d1651 100644 --- a/src/HttpClient/RequestBuilder.php +++ b/src/HttpClient/RequestBuilder.php @@ -130,8 +130,7 @@ private function createRequest( string $uri, array $headers, StreamInterface $stream - ): RequestInterface - { + ): RequestInterface { $request = $this->getRequestFactory()->createRequest($method, $uri); $request = $request->withBody($stream); foreach ($headers as $name => $value) { diff --git a/src/Hydrator/ModelHydrator.php b/src/Hydrator/ModelHydrator.php index a51e9f2b..fd0c2d66 100644 --- a/src/Hydrator/ModelHydrator.php +++ b/src/Hydrator/ModelHydrator.php @@ -26,6 +26,7 @@ final class ModelHydrator implements Hydrator * @param class-string $class * * @throws HydrationException + * * @return ResponseInterface */ public function hydrate(ResponseInterface $response, string $class) diff --git a/src/Hydrator/NoopHydrator.php b/src/Hydrator/NoopHydrator.php index 76a39e32..6b8a0467 100644 --- a/src/Hydrator/NoopHydrator.php +++ b/src/Hydrator/NoopHydrator.php @@ -24,6 +24,7 @@ final class NoopHydrator implements Hydrator * @param class-string $class * * @throws \LogicException + * * @return never */ public function hydrate(ResponseInterface $response, string $class) diff --git a/src/Message/Exceptions/LimitExceeded.php b/src/Message/Exceptions/LimitExceeded.php index c0fd0b4d..fae151dc 100644 --- a/src/Message/Exceptions/LimitExceeded.php +++ b/src/Message/Exceptions/LimitExceeded.php @@ -15,7 +15,7 @@ class LimitExceeded extends \Exception implements Exception { - public static function create(string $field, int $limit): self + public static function create(string $field, int $limit) { return new self(sprintf('You\'ve exceeded the maximum (%d) %s for a single message.', $limit, $field)); } diff --git a/src/Message/Exceptions/TooManyRecipients.php b/src/Message/Exceptions/TooManyRecipients.php index 4cf1f55f..29f47a3f 100644 --- a/src/Message/Exceptions/TooManyRecipients.php +++ b/src/Message/Exceptions/TooManyRecipients.php @@ -16,12 +16,12 @@ class TooManyRecipients extends LimitExceeded implements Exception { - public static function create(string $field, int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT): self + public static function create(string $field, int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT) { return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) for filed "%s".', $limit, $field)); } - public static function whenAutoSendDisabled(int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT): self + public static function whenAutoSendDisabled(int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT) { return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) with autosend disabled.', $limit)); }