diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index c51bb826..358c1f88 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -50,7 +50,7 @@ abstract class HttpApi * @param RequestBuilder $requestBuilder * @param Hydrator $hydrator */ - public function __construct($httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator) + public function __construct(ClientInterface $httpClient, RequestBuilder $requestBuilder, Hydrator $hydrator) { $this->httpClient = $httpClient; $this->requestBuilder = $requestBuilder; diff --git a/src/Api/MailingList/Member.php b/src/Api/MailingList/Member.php index b91e949d..ee9c725f 100644 --- a/src/Api/MailingList/Member.php +++ b/src/Api/MailingList/Member.php @@ -120,14 +120,14 @@ public function create( /** * Adds multiple members (up to 1000) to the mailing list. - * @param string $list Address of the mailing list - * @param array $members Array of members, each item should be either a single string address or an array of member properties - * @param bool $upsert `true` to update existing members, `false` (default) to ignore duplicates - * @param array $requestHeaders - * @return UpdateResponse + * @param string $list Address of the mailing list + * @param array $members Array of members, each item should be either a single string address or an array of member properties + * @param bool $upsert `true` to update existing members, `false` (default) to ignore duplicates + * @param array $requestHeaders + * @return MailingListUpdateResponse|null * @throws ClientExceptionInterface */ - public function createMultiple(string $list, array $members, bool $upsert = false, array $requestHeaders = []) + public function createMultiple(string $list, array $members, bool $upsert = false, array $requestHeaders = []): ?MailingListUpdateResponse { Assert::stringNotEmpty($list); Assert::isArray($members); @@ -156,11 +156,11 @@ public function createMultiple(string $list, array $members, bool $upsert = fals if (is_array($value)) { $value = json_encode($value); } - // We should assert that "vars"'s $value is a string. + break; + // We should assert that "vars"'s $value is a string. // no break case 'name': Assert::string($value); - break; case 'subscribed': Assert::oneOf($value, ['yes', 'no', true, false]); diff --git a/src/Api/Pagination.php b/src/Api/Pagination.php index 2640adcd..970bcb38 100644 --- a/src/Api/Pagination.php +++ b/src/Api/Pagination.php @@ -21,10 +21,19 @@ */ trait Pagination { + /** + * @param string $path + * @param array $parameters + * @param array $requestHeaders + * @return ResponseInterface + */ abstract protected function httpGet(string $path, array $parameters = [], array $requestHeaders = []): ResponseInterface; + /** * @param class-string $className + * @param ResponseInterface $response + * @return mixed */ abstract protected function hydrateResponse(ResponseInterface $response, string $className); @@ -49,8 +58,9 @@ public function previousPage(PagingProvider $response): ?PagingProvider } /** - * @param PagingProvider $response + * @param PagingProvider $response * @return PagingProvider|null + * @throws ClientExceptionInterface */ public function firstPage(PagingProvider $response): ?PagingProvider { diff --git a/src/Api/Templates.php b/src/Api/Templates.php index ec665141..dbfd8cf1 100644 --- a/src/Api/Templates.php +++ b/src/Api/Templates.php @@ -47,7 +47,7 @@ public function index(string $domain, int $limit, string $page, string $pivot, a $params = [ 'limit' => $limit, - 'skip' => $page, + 'page' => $page, 'p' => $pivot, ]; diff --git a/src/Assert.php b/src/Assert.php index 19c1b7fa..58052b85 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -20,7 +20,13 @@ */ final class Assert extends \Webmozart\Assert\Assert { - protected static function reportInvalidArgument($message) + /** + * @psalm-pure this method is not supposed to perform side-effects + * @psalm-return never + * @param mixed $message + * @return void + */ + protected static function reportInvalidArgument($message): void { throw new InvalidArgumentException($message); } diff --git a/src/HttpClient/HttpClientConfigurator.php b/src/HttpClient/HttpClientConfigurator.php index e2eff912..eba1616e 100644 --- a/src/HttpClient/HttpClientConfigurator.php +++ b/src/HttpClient/HttpClientConfigurator.php @@ -101,6 +101,10 @@ public function createConfiguredClient(): PluginClient return new PluginClient($this->getHttpClient(), $plugins); } + /** + * @param bool $debug + * @return $this + */ public function setDebug(bool $debug): self { $this->debug = $debug; @@ -108,6 +112,10 @@ public function setDebug(bool $debug): self return $this; } + /** + * @param string $endpoint + * @return $this + */ public function setEndpoint(string $endpoint): self { $this->endpoint = $endpoint; @@ -115,11 +123,18 @@ public function setEndpoint(string $endpoint): self return $this; } + /** + * @return string + */ public function getApiKey(): string { return $this->apiKey; } + /** + * @param string $apiKey + * @return $this + */ public function setApiKey(string $apiKey): self { $this->apiKey = $apiKey; @@ -127,6 +142,9 @@ public function setApiKey(string $apiKey): self return $this; } + /** + * @return UriFactoryInterface + */ private function getUriFactory(): UriFactoryInterface { if (null === $this->uriFactory) { @@ -136,6 +154,10 @@ private function getUriFactory(): UriFactoryInterface return $this->uriFactory; } + /** + * @param UriFactoryInterface $uriFactory + * @return $this + */ public function setUriFactory(UriFactoryInterface $uriFactory): self { $this->uriFactory = $uriFactory; @@ -143,6 +165,9 @@ public function setUriFactory(UriFactoryInterface $uriFactory): self return $this; } + /** + * @return ClientInterface + */ private function getHttpClient(): ClientInterface { if (null === $this->httpClient) { @@ -152,6 +177,10 @@ private function getHttpClient(): ClientInterface return $this->httpClient; } + /** + * @param ClientInterface $httpClient + * @return $this + */ public function setHttpClient(ClientInterface $httpClient): self { $this->httpClient = $httpClient; @@ -159,6 +188,9 @@ public function setHttpClient(ClientInterface $httpClient): self return $this; } + /** + * @return History + */ public function getResponseHistory(): History { return $this->responseHistory; diff --git a/src/HttpClient/Plugin/ReplaceUriPlugin.php b/src/HttpClient/Plugin/ReplaceUriPlugin.php index 21cf0845..b909e287 100644 --- a/src/HttpClient/Plugin/ReplaceUriPlugin.php +++ b/src/HttpClient/Plugin/ReplaceUriPlugin.php @@ -29,11 +29,20 @@ final class ReplaceUriPlugin implements Plugin */ private $uri; + /** + * @param UriInterface $uri + */ public function __construct(UriInterface $uri) { $this->uri = $uri; } + /** + * @param RequestInterface $request + * @param callable $next + * @param callable $first + * @return mixed + */ public function doHandleRequest(RequestInterface $request, callable $next, callable $first) { $request = $request->withUri($this->uri); diff --git a/src/HttpClient/RequestBuilder.php b/src/HttpClient/RequestBuilder.php index 7ca17154..5ee230d3 100644 --- a/src/HttpClient/RequestBuilder.php +++ b/src/HttpClient/RequestBuilder.php @@ -40,7 +40,9 @@ class RequestBuilder /** * Creates a new PSR-7 request. - * + * @param string $method HTTP method + * @param string $uri URI + * @param array $headers Request headers * @param array|string|null $body Request body. If body is an array we will send a as multipart stream request. * If array, each array *item* MUST look like: * array ( @@ -53,7 +55,7 @@ class RequestBuilder public function create(string $method, string $uri, array $headers = [], $body = null): RequestInterface { if (!is_array($body)) { - $stream = $this->getStreamFactory()->createStream((string) $body); + $stream = $this->getStreamFactory()->createStream((string)$body); return $this->createRequest($method, $uri, $headers, $stream); } @@ -62,8 +64,7 @@ public function create(string $method, string $uri, array $headers = [], $body = foreach ($body as $item) { $name = $this->getItemValue($item, 'name'); $content = $this->getItemValue($item, 'content'); - unset($item['name']); - unset($item['content']); + unset($item['name'], $item['content']); $builder->addResource($name, $content, $item); } @@ -72,7 +73,7 @@ public function create(string $method, string $uri, array $headers = [], $body = $boundary = $builder->getBoundary(); $builder->reset(); - $headers['Content-Type'] = 'multipart/form-data; boundary="'.$boundary.'"'; + $headers['Content-Type'] = 'multipart/form-data; boundary="' . $boundary . '"'; return $this->createRequest($method, $uri, $headers, $multipartStream); } @@ -90,7 +91,7 @@ private function getRequestFactory(): RequestFactoryInterface } /** - * @param RequestFactoryInterface $requestFactory + * @param RequestFactoryInterface $requestFactory * @return $this */ public function setRequestFactory(RequestFactoryInterface $requestFactory): self @@ -113,7 +114,7 @@ private function getStreamFactory(): StreamFactoryInterface } /** - * @param StreamFactoryInterface $streamFactory + * @param StreamFactoryInterface $streamFactory * @return $this */ public function setStreamFactory(StreamFactoryInterface $streamFactory): self @@ -136,7 +137,7 @@ private function getMultipartStreamBuilder(): MultipartStreamBuilder } /** - * @param MultipartStreamBuilder $multipartStreamBuilder + * @param MultipartStreamBuilder $multipartStreamBuilder * @return $this */ public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStreamBuilder): self @@ -147,10 +148,10 @@ public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStrea } /** - * @param string $method - * @param string $uri - * @param array $headers - * @param StreamInterface $stream + * @param string $method + * @param string $uri + * @param array $headers + * @param StreamInterface $stream * @return RequestInterface */ private function createRequest(string $method, string $uri, array $headers, StreamInterface $stream): RequestInterface @@ -165,14 +166,14 @@ private function createRequest(string $method, string $uri, array $headers, Stre } /** - * @param array $item - * @param string $key + * @param array $item + * @param string $key * @return mixed|string */ private function getItemValue(array $item, string $key) { if (is_bool($item[$key])) { - return (string) $item[$key]; + return (string)$item[$key]; } return $item[$key]; diff --git a/src/Mailgun.php b/src/Mailgun.php index b7649a5e..9d9f53c7 100644 --- a/src/Mailgun.php +++ b/src/Mailgun.php @@ -220,7 +220,7 @@ public function tags(): Api\Tag */ public function webhooks(): Api\Webhook { - return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator, $this->apiKey); + return new Api\Webhook($this->httpClient, $this->requestBuilder, $this->hydrator, $this->apiKey ?? ''); } /** diff --git a/src/Message/BatchMessage.php b/src/Message/BatchMessage.php index ea16191d..4ed03be1 100644 --- a/src/Message/BatchMessage.php +++ b/src/Message/BatchMessage.php @@ -70,10 +70,9 @@ public function __construct(Message $messageApi, string $domain, bool $autoSend) * full_name?: string, * first?: string, * last?: string, - * * @return MessageBuilder * @throws MissingRequiredParameter - * @throws TooManyRecipients + * @throws TooManyRecipients|ClientExceptionInterface */ protected function addRecipient(string $headerName, string $address, array $variables): MessageBuilder { diff --git a/src/Message/Exceptions/LimitExceeded.php b/src/Message/Exceptions/LimitExceeded.php index fae151dc..ae801ce0 100644 --- a/src/Message/Exceptions/LimitExceeded.php +++ b/src/Message/Exceptions/LimitExceeded.php @@ -15,6 +15,11 @@ class LimitExceeded extends \Exception implements Exception { + /** + * @param string $field + * @param int $limit + * @return 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/MissingRequiredParameter.php b/src/Message/Exceptions/MissingRequiredParameter.php index a4925f1c..02104aff 100644 --- a/src/Message/Exceptions/MissingRequiredParameter.php +++ b/src/Message/Exceptions/MissingRequiredParameter.php @@ -15,6 +15,11 @@ class MissingRequiredParameter extends \Exception implements Exception { + /** + * @param string $parameter + * @param string|null $message + * @return self + */ public static function create(string $parameter, string $message = null) { if (null === $message) { diff --git a/src/Message/Exceptions/TooManyRecipients.php b/src/Message/Exceptions/TooManyRecipients.php index 29f47a3f..697f386f 100644 --- a/src/Message/Exceptions/TooManyRecipients.php +++ b/src/Message/Exceptions/TooManyRecipients.php @@ -16,11 +16,20 @@ class TooManyRecipients extends LimitExceeded implements Exception { + /** + * @param string $field + * @param int $limit + * @return LimitExceeded|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)); } + /** + * @param int $limit + * @return 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)); diff --git a/src/Message/MessageBuilder.php b/src/Message/MessageBuilder.php index 604f21bd..6110bdff 100644 --- a/src/Message/MessageBuilder.php +++ b/src/Message/MessageBuilder.php @@ -61,8 +61,9 @@ class MessageBuilder ]; /** - * @param array $params - * @param string $key + * @param array $params + * @param string $key + * @param mixed $default * @return mixed */ private function get(array $params, string $key, $default) @@ -75,7 +76,7 @@ private function get(array $params, string $key, $default) } /** - * @param array $params { + * @param array $params { * full_name?: * string, * first?: @@ -152,9 +153,8 @@ protected function addRecipient(string $headerName, string $address, array $vari * first?: string, * last?: string, * } - * * @return MessageBuilder - * @throws TooManyRecipients + * @throws TooManyRecipients|LimitExceeded */ public function addToRecipient(string $address, array $variables = []): self { @@ -174,9 +174,8 @@ public function addToRecipient(string $address, array $variables = []): self * first?: string, * last?: string, * } - * * @return MessageBuilder - * @throws TooManyRecipients + * @throws TooManyRecipients|LimitExceeded */ public function addCcRecipient(string $address, array $variables = []): self { @@ -197,9 +196,8 @@ public function addCcRecipient(string $address, array $variables = []): self * first?: string, * last?: string, * } - * * @return MessageBuilder - * @throws TooManyRecipients + * @throws TooManyRecipients|LimitExceeded */ public function addBccRecipient(string $address, array $variables = []): self { @@ -270,7 +268,8 @@ public function setTemplate(string $template): self } /** - * @param string $headerName + * @param string $headerName + * @param mixed $headerData * @return $this */ public function addCustomHeader(string $headerName, $headerData): self @@ -391,7 +390,7 @@ public function addCampaignId(string $campaignId): self throw LimitExceeded::create('campaigns', self::CAMPAIGN_ID_LIMIT); } if (isset($this->message['o:campaign'])) { - array_push($this->message['o:campaign'], $campaignId); + $this->message['o:campaign'][] = $campaignId; } else { $this->message['o:campaign'] = [$campaignId]; } @@ -410,7 +409,7 @@ public function addTag(string $tag): self } if (isset($this->message['o:tag'])) { - array_push($this->message['o:tag'], $tag); + $this->message['o:tag'][] = $tag; } else { $this->message['o:tag'] = [$tag]; } @@ -483,7 +482,8 @@ public function setDeliveryTime(string $timeDate, string $timeZone = null): self } /** - * @param string $customName + * @param string $customName + * @param mixed $data * @return $this */ public function addCustomData(string $customName, $data): self @@ -494,7 +494,8 @@ public function addCustomData(string $customName, $data): self } /** - * @param string $parameterName + * @param string $parameterName + * @param mixed $data * @return $this */ public function addCustomParameter(string $parameterName, $data): self diff --git a/src/Model/MailingList/UpdateResponse.php b/src/Model/MailingList/UpdateResponse.php index f7a29ba3..a2f8af8a 100644 --- a/src/Model/MailingList/UpdateResponse.php +++ b/src/Model/MailingList/UpdateResponse.php @@ -18,6 +18,10 @@ final class UpdateResponse implements ApiResponse private $message; private $list; + /** + * @param array $data + * @return self + */ public static function create(array $data): self { $model = new self(); @@ -31,11 +35,17 @@ private function __construct() { } + /** + * @return string + */ public function getMessage(): string { return $this->message; } + /** + * @return MailingList + */ public function getList(): MailingList { return $this->list;