Skip to content

Commit 276ad24

Browse files
Fix some missing or inaccurate return/throw types.
1 parent 6853b03 commit 276ad24

21 files changed

+51
-45
lines changed

src/Api/Attachment.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
namespace Mailgun\Api;
1313

1414
use Mailgun\Assert;
15+
use Mailgun\Exception\{
16+
HttpClientException,
17+
HttpServerException,
18+
UnknownErrorException
19+
};
1520
use Psr\Http\Message\ResponseInterface;
1621

1722
/**
@@ -20,9 +25,9 @@
2025
class Attachment extends HttpApi
2126
{
2227
/**
23-
* @return ResponseInterface
28+
* @throws HttpClientException|HttpServerException|UnknownErrorException
2429
*/
25-
public function show(string $url)
30+
public function show(string $url): ResponseInterface
2631
{
2732
Assert::stringNotEmpty($url);
2833
Assert::regex($url, '@https://.*mailgun\.(net|org)/v.+@');

src/Api/EmailValidationV4.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,8 @@ public function getBulkPreview(string $previewId)
199199

200200
/**
201201
* @param string $previewId ID given when the list created
202-
*
203-
* @return bool
204202
*/
205-
public function deleteBulkPreview(string $previewId)
203+
public function deleteBulkPreview(string $previewId): bool
206204
{
207205
Assert::stringNotEmpty($previewId);
208206

src/Api/HttpApi.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ protected function hydrateResponse(ResponseInterface $response, string $class)
8181
/**
8282
* Throw the correct exception for this error.
8383
*
84-
* @throws \Exception
84+
* @throws HttpClientException|HttpServerException|UnknownErrorException
85+
* @return never
8586
*/
86-
protected function handleErrors(ResponseInterface $response)
87+
protected function handleErrors(ResponseInterface $response): void
8788
{
8889
$statusCode = $response->getStatusCode();
8990
switch ($statusCode) {

src/Assert.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
*/
2121
final class Assert extends \Webmozart\Assert\Assert
2222
{
23-
protected static function reportInvalidArgument($message)
23+
/**
24+
* @throws InvalidArgumentException
25+
* @return never
26+
*/
27+
protected static function reportInvalidArgument($message): void
2428
{
2529
throw new InvalidArgumentException($message);
2630
}

src/Exception/HttpClientException.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(string $message, int $code, ResponseInterface $respo
4848
}
4949
}
5050

51-
public static function badRequest(ResponseInterface $response)
51+
public static function badRequest(ResponseInterface $response): self
5252
{
5353
$body = $response->getBody()->__toString();
5454
if (0 !== strpos($response->getHeaderLine('Content-Type'), 'application/json')) {
@@ -63,37 +63,37 @@ public static function badRequest(ResponseInterface $response)
6363
return new self($message, 400, $response);
6464
}
6565

66-
public static function unauthorized(ResponseInterface $response)
66+
public static function unauthorized(ResponseInterface $response): self
6767
{
6868
return new self('Your credentials are incorrect.', 401, $response);
6969
}
7070

71-
public static function requestFailed(ResponseInterface $response)
71+
public static function requestFailed(ResponseInterface $response): self
7272
{
7373
return new self('Parameters were valid but request failed. Try again.', 402, $response);
7474
}
7575

76-
public static function notFound(ResponseInterface $response)
76+
public static function notFound(ResponseInterface $response): self
7777
{
7878
return new self('The endpoint you have tried to access does not exist. Check if the domain matches the domain you have configure on Mailgun.', 404, $response);
7979
}
8080

81-
public static function conflict(ResponseInterface $response)
81+
public static function conflict(ResponseInterface $response): self
8282
{
8383
return new self('Request conflicts with current state of the target resource.', 409, $response);
8484
}
8585

86-
public static function payloadTooLarge(ResponseInterface $response)
86+
public static function payloadTooLarge(ResponseInterface $response): self
8787
{
8888
return new self('Payload too large, your total attachment size is too big.', 413, $response);
8989
}
9090

91-
public static function tooManyRequests(ResponseInterface $response)
91+
public static function tooManyRequests(ResponseInterface $response): self
9292
{
9393
return new self('Too many requests.', 429, $response);
9494
}
9595

96-
public static function forbidden(ResponseInterface $response)
96+
public static function forbidden(ResponseInterface $response): self
9797
{
9898
$body = $response->getBody()->__toString();
9999
if (0 !== strpos($response->getHeaderLine('Content-Type'), 'application/json')) {

src/Exception/HttpServerException.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
*/
1919
final class HttpServerException extends \RuntimeException implements Exception
2020
{
21-
public static function serverError(int $httpStatus = 500)
21+
public static function serverError(int $httpStatus = 500): self
2222
{
2323
return new self('An unexpected error occurred at Mailgun\'s servers. Try again later and contact support if the error still exists.', $httpStatus);
2424
}
2525

26-
public static function networkError(\Throwable $previous)
26+
public static function networkError(\Throwable $previous): self
2727
{
2828
return new self('Mailgun\'s servers are currently unreachable.', 0, $previous);
2929
}
3030

31-
public static function unknownHttpResponseCode(int $code)
31+
public static function unknownHttpResponseCode(int $code): self
3232
{
3333
return new self(sprintf('Unknown HTTP response code ("%d") received from the API server', $code));
3434
}

src/HttpClient/Plugin/History.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ final class History implements Journal
2828
*/
2929
private $lastResponse;
3030

31-
/**
32-
* @return ResponseInterface|null
33-
*/
34-
public function getLastResponse()
31+
public function getLastResponse(): ?ResponseInterface
3532
{
3633
return $this->lastResponse;
3734
}
3835

39-
public function addSuccess(RequestInterface $request, ResponseInterface $response)
36+
public function addSuccess(RequestInterface $request, ResponseInterface $response): void
4037
{
4138
$this->lastResponse = $response;
4239
}

src/HttpClient/RequestBuilder.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStrea
125125
return $this;
126126
}
127127

128-
private function createRequest(string $method, string $uri, array $headers, StreamInterface $stream)
128+
private function createRequest(
129+
string $method,
130+
string $uri,
131+
array $headers,
132+
StreamInterface $stream
133+
): RequestInterface
129134
{
130135
$request = $this->getRequestFactory()->createRequest($method, $uri);
131136
$request = $request->withBody($stream);

src/Hydrator/ArrayHydrator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ final class ArrayHydrator implements Hydrator
2424
/**
2525
* @param class-string $class
2626
*
27-
* @return array
27+
* @throws HydrationException
2828
*/
29-
public function hydrate(ResponseInterface $response, string $class)
29+
public function hydrate(ResponseInterface $response, string $class): array
3030
{
3131
$body = $response->getBody()->__toString();
3232
if (0 !== strpos($response->getHeaderLine('Content-Type'), 'application/json')) {

src/Hydrator/ModelHydrator.php

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ final class ModelHydrator implements Hydrator
2525
/**
2626
* @param class-string $class
2727
*
28+
* @throws HydrationException
2829
* @return ResponseInterface
2930
*/
3031
public function hydrate(ResponseInterface $response, string $class)

src/Hydrator/NoopHydrator.php

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class NoopHydrator implements Hydrator
2424
* @param class-string $class
2525
*
2626
* @throws \LogicException
27+
* @return never
2728
*/
2829
public function hydrate(ResponseInterface $response, string $class)
2930
{

src/Message/Exceptions/LimitExceeded.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class LimitExceeded extends \Exception implements Exception
1717
{
18-
public static function create(string $field, int $limit)
18+
public static function create(string $field, int $limit): self
1919
{
2020
return new self(sprintf('You\'ve exceeded the maximum (%d) %s for a single message.', $limit, $field));
2121
}

src/Message/Exceptions/MissingRequiredParameter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class MissingRequiredParameter extends \Exception implements Exception
1717
{
18-
public static function create(string $parameter, string $message = null)
18+
public static function create(string $parameter, string $message = null): self
1919
{
2020
if (null === $message) {
2121
$message = 'The parameters passed to the API were invalid. Please specify "%s".';

src/Message/Exceptions/TooManyRecipients.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
class TooManyRecipients extends LimitExceeded implements Exception
1818
{
19-
public static function create(string $field, int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT)
19+
public static function create(string $field, int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT): self
2020
{
2121
return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) for filed "%s".', $limit, $field));
2222
}
2323

24-
public static function whenAutoSendDisabled(int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT)
24+
public static function whenAutoSendDisabled(int $limit = MessageBuilder::RECIPIENT_COUNT_LIMIT): self
2525
{
2626
return new self(sprintf('You\'ve exceeded the maximum recipient count (%s) with autosend disabled.', $limit));
2727
}

src/Model/EmailValidation/Parts.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ private function __construct()
3535
{
3636
}
3737

38-
/**
39-
* @return Parts
40-
*/
41-
public static function create(array $data)
38+
public static function create(array $data): self
4239
{
4340
$model = new self();
4441
$model->displayName = $data['display_name'] ?? null;

src/Model/Event/EventResponse.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private function __construct()
2727
{
2828
}
2929

30-
public static function create(array $data)
30+
public static function create(array $data): self
3131
{
3232
$events = [];
3333
if (isset($data['items'])) {

src/Model/Ip/IndexResponse.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private function __construct()
3737
{
3838
}
3939

40-
public static function create(array $data)
40+
public static function create(array $data): self
4141
{
4242
$model = new self();
4343
$model->items = $data['items'];

src/Model/Ip/ShowResponse.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private function __construct()
2626
{
2727
}
2828

29-
public static function create(array $data)
29+
public static function create(array $data): self
3030
{
3131
$model = new self();
3232
$model->ip = $data['ip'];

src/Model/Ip/UpdateResponse.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private function __construct()
2424
{
2525
}
2626

27-
public static function create(array $data)
27+
public static function create(array $data): self
2828
{
2929
$model = new self();
3030
$model->message = $data['message'];

src/Model/MailingList/PagesResponse.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ final class PagesResponse implements ApiResponse, PagingProvider
2121

2222
private $items;
2323

24-
/**
25-
* @return self
26-
*/
27-
public static function create(array $data)
24+
public static function create(array $data): self
2825
{
2926
$items = [];
3027

src/Model/Route/Action.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ final class Action
2121
/**
2222
* Action Named Constructor to build several Action DTOs provided by an Array.
2323
*
24-
* @return Action[]
24+
* @return self[]
2525
*/
26-
public static function createMultiple(array $data)
26+
public static function createMultiple(array $data): array
2727
{
2828
$items = [];
2929

0 commit comments

Comments
 (0)