From 34432e0517d3a2224c9c782d88963675107a278c Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 9 Jan 2019 20:52:17 +0100 Subject: [PATCH] Minor bugfixes detected with PHPStan --- src/Api/HttpApi.php | 4 ++-- src/Api/MailingList/Member.php | 6 ++--- src/Api/Route.php | 2 +- src/Mailgun.php | 5 ++++- src/Message/BatchMessage.php | 2 +- src/Message/MessageBuilder.php | 4 ++-- src/Model/Domain/ConnectionResponse.php | 7 ++---- src/Model/Event/Event.php | 12 +++++----- src/Model/PaginationResponse.php | 29 ++++++++----------------- src/Model/Route/Action.php | 8 +------ src/Model/Stats/AllResponseItem.php | 2 +- 11 files changed, 32 insertions(+), 49 deletions(-) diff --git a/src/Api/HttpApi.php b/src/Api/HttpApi.php index 1bb287a..31ed4fb 100644 --- a/src/Api/HttpApi.php +++ b/src/Api/HttpApi.php @@ -34,7 +34,7 @@ abstract class HttpApi protected $httpClient; /** - * @var Hydrator + * @var null|Hydrator */ protected $hydrator; @@ -59,7 +59,7 @@ abstract class HttpApi */ protected function hydrateResponse(ResponseInterface $response, string $class) { - if (!$this->hydrator) { + if (null === $this->hydrator) { return $response; } diff --git a/src/Api/MailingList/Member.php b/src/Api/MailingList/Member.php index 9bd95c7..6bc3a74 100644 --- a/src/Api/MailingList/Member.php +++ b/src/Api/MailingList/Member.php @@ -26,9 +26,9 @@ class Member extends HttpApi /** * Returns a paginated list of members of the mailing list. * - * @param string $address Address of the mailing list - * @param int $limit Maximum number of records to return (optional: 100 by default) - * @param string|null $subscribed `true` to lists subscribed, `false` for unsubscribed. list all if null + * @param string $address Address of the mailing list + * @param int $limit Maximum number of records to return (optional: 100 by default) + * @param bool|null $subscribed `true` to lists subscribed, `false` for unsubscribed. list all if null * * @return IndexResponse * diff --git a/src/Api/Route.php b/src/Api/Route.php index 1c43ac1..066fc22 100644 --- a/src/Api/Route.php +++ b/src/Api/Route.php @@ -96,7 +96,7 @@ class Route extends HttpApi * * @param string $routeId Route ID returned by the Routes::index() method * @param string|null $expression A filter expression like "match_recipient('.*@gmail.com')" - * @param array|null $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('alice@example.com')" + * @param array $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('alice@example.com')" * @param string|null $description An arbitrary string * @param int|null $priority Integer: smaller number indicates higher priority. Higher priority routes are handled first. Defaults to 0. * diff --git a/src/Mailgun.php b/src/Mailgun.php index 091bd0e..fe2a672 100644 --- a/src/Mailgun.php +++ b/src/Mailgun.php @@ -12,7 +12,10 @@ declare(strict_types=1); namespace Mailgun; use Http\Client\Common\HttpMethodsClient; +use Http\Client\HttpClient; +use Mailgun\HttpClient\HttpClientConfigurator; use Mailgun\HttpClient\Plugin\History; +use Mailgun\HttpClient\RequestBuilder; use Mailgun\Hydrator\ModelHydrator; use Mailgun\Hydrator\Hydrator; use Psr\Http\Message\ResponseInterface; @@ -28,7 +31,7 @@ final class Mailgun private $apiKey; /** - * @var HttpMethodsClient + * @var HttpClient */ private $httpClient; diff --git a/src/Message/BatchMessage.php b/src/Message/BatchMessage.php index 86af2d7..a039243 100644 --- a/src/Message/BatchMessage.php +++ b/src/Message/BatchMessage.php @@ -85,7 +85,7 @@ class BatchMessage extends MessageBuilder $variables['id'] = $headerName.'_'.$this->counters['recipients'][$headerName]; } - $this->batchRecipientAttributes[(string) $address] = $variables; + $this->batchRecipientAttributes[$address] = $variables; return $this; } diff --git a/src/Message/MessageBuilder.php b/src/Message/MessageBuilder.php index 22d1b22..3d7ac60 100644 --- a/src/Message/MessageBuilder.php +++ b/src/Message/MessageBuilder.php @@ -306,9 +306,9 @@ class MessageBuilder throw LimitExceeded::create('campaigns', self::CAMPAIGN_ID_LIMIT); } if (isset($this->message['o:campaign'])) { - array_push($this->message['o:campaign'], (string) $campaignId); + array_push($this->message['o:campaign'], $campaignId); } else { - $this->message['o:campaign'] = [(string) $campaignId]; + $this->message['o:campaign'] = [$campaignId]; } ++$this->counters['attributes']['campaign_id']; diff --git a/src/Model/Domain/ConnectionResponse.php b/src/Model/Domain/ConnectionResponse.php index 0d41e1a..a8c6818 100644 --- a/src/Model/Domain/ConnectionResponse.php +++ b/src/Model/Domain/ConnectionResponse.php @@ -28,13 +28,10 @@ final class ConnectionResponse implements ApiResponse */ private $requireTLS; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): ?self { if (!isset($data['connection'])) { - return; + return null; } $connSettings = $data['connection']; diff --git a/src/Model/Event/Event.php b/src/Model/Event/Event.php index 28f02d0..5ce5bd0 100644 --- a/src/Model/Event/Event.php +++ b/src/Model/Event/Event.php @@ -39,7 +39,7 @@ final class Event private $eventDate; /** - * @var array|string[] + * @var string[] */ private $tags = []; @@ -64,7 +64,7 @@ final class Event private $deliveryStatus; /** - * @var array|string[] + * @var string[] */ private $campaigns = []; @@ -232,7 +232,7 @@ final class Event } /** - * @return array|\string[] + * @return string[] */ public function getTags() { @@ -240,7 +240,7 @@ final class Event } /** - * @param array|\string[] $tags + * @param string[] $tags */ private function setTags($tags) { @@ -296,7 +296,7 @@ final class Event } /** - * @return array|\string[] + * @return string[] */ public function getCampaigns() { @@ -304,7 +304,7 @@ final class Event } /** - * @param array|\string[] $campaigns + * @param string[] $campaigns */ private function setCampaigns($campaigns) { diff --git a/src/Model/PaginationResponse.php b/src/Model/PaginationResponse.php index 503b0dc..1e88084 100644 --- a/src/Model/PaginationResponse.php +++ b/src/Model/PaginationResponse.php @@ -21,49 +21,38 @@ trait PaginationResponse */ protected $paging; - /** - * @return string - */ - public function getNextUrl() + public function getNextUrl(): ?string { if (!isset($this->paging['next'])) { - return; + return null; } return $this->paging['next']; } - /** - * @return string - */ - public function getPreviousUrl() + + public function getPreviousUrl(): ?string { if (!isset($this->paging['previous'])) { - return; + return null; } return $this->paging['previous']; } - /** - * @return string - */ - public function getFirstUrl() + public function getFirstUrl(): ?string { if (!isset($this->paging['first'])) { - return; + return null; } return $this->paging['first']; } - /** - * @return string - */ - public function getLastUrl() + public function getLastUrl(): ?string { if (!isset($this->paging['last'])) { - return; + return null; } return $this->paging['last']; diff --git a/src/Model/Route/Action.php b/src/Model/Route/Action.php index a00a97d..134ec63 100644 --- a/src/Model/Route/Action.php +++ b/src/Model/Route/Action.php @@ -24,7 +24,6 @@ final class Action /** * Action Named Constructor to build several Action DTOs provided by an Array. * - * * @return Action[] */ public static function createMultiple(array $data) @@ -38,12 +37,7 @@ final class Action return $items; } - /** - * Action Private Constructor. - * - * @param $action - */ - private function __construct($action) + private function __construct(string $action) { $this->action = $action; } diff --git a/src/Model/Stats/AllResponseItem.php b/src/Model/Stats/AllResponseItem.php index f443498..980c4a5 100644 --- a/src/Model/Stats/AllResponseItem.php +++ b/src/Model/Stats/AllResponseItem.php @@ -59,7 +59,7 @@ final class AllResponseItem * @param string $id * @param string $event * @param string $totalCount - * @param \string[] $tags + * @param string[] $tags */ private function __construct($id, $event, $totalCount, array $tags, \DateTime $createdAt) {