diff --git a/src/Model/MailingList/CreateResponse.php b/src/Model/MailingList/CreateResponse.php index 0f62ad5..14e8a09 100644 --- a/src/Model/MailingList/CreateResponse.php +++ b/src/Model/MailingList/CreateResponse.php @@ -15,45 +15,28 @@ use Mailgun\Model\ApiResponse; final class CreateResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var MailingList - */ private $list; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - $message = isset($data['message']) ? $data['message'] : ''; - $list = MailingList::create($data['list']); + $model = new self(); + $model->list = MailingList::create($data['list']); + $model->message = $data['message'] ?? ''; - return new self($list, $message); + return $model; } - private function __construct(MailingList $list, $message) + private function __construct() { - $this->list = $list; - $this->message = $message; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } - /** - * @return MailingList - */ - public function getList() + public function getList(): MailingList { return $this->list; } diff --git a/src/Model/MailingList/DeleteResponse.php b/src/Model/MailingList/DeleteResponse.php index ddd64ef..f503387 100644 --- a/src/Model/MailingList/DeleteResponse.php +++ b/src/Model/MailingList/DeleteResponse.php @@ -15,48 +15,28 @@ use Mailgun\Model\ApiResponse; final class DeleteResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var string - */ private $address; - public static function create(array $data) + public static function create(array $data): self { - $message = isset($data['message']) ? $data['message'] : ''; - $address = isset($data['address']) ? $data['address'] : ''; + $model = new self(); + $model->address = $data['address'] ?? ''; + $model->message = $data['message'] ?? ''; - return new self($address, $message); + return $model; } - /** - * DeleteResponse constructor. - * - * @param string $address - * @param string $message - */ - private function __construct($address, $message) + private function __construct() { - $this->address = $address; - $this->message = $message; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): string { return $this->address; } diff --git a/src/Model/MailingList/MailingList.php b/src/Model/MailingList/MailingList.php index 4868223..801c167 100644 --- a/src/Model/MailingList/MailingList.php +++ b/src/Model/MailingList/MailingList.php @@ -15,114 +15,56 @@ use Mailgun\Model\ApiResponse; final class MailingList implements ApiResponse { - /** - * @var string - */ private $name; - - /** - * @var string - */ private $address; - - /** - * @var string - */ private $accessLevel; - - /** - * @var string - */ private $description; - - /** - * @var int - */ private $membersCount; - - /** - * @var \DateTime - */ private $createdAt; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - return new self( - isset($data['name']) ? $data['name'] : null, - isset($data['address']) ? $data['address'] : null, - isset($data['access_level']) ? $data['access_level'] : null, - isset($data['description']) ? $data['description'] : null, - isset($data['members_count']) ? $data['members_count'] : null, - isset($data['created_at']) ? new \DateTime($data['created_at']) : null - ); + $model = new self(); + $model->name = $data['name'] ?? null; + $model->address = $data['address'] ?? null; + $model->accessLevel = $data['access_level'] ?? null; + $model->description = $data['description'] ?? null; + $model->membersCount = (int) ($data['members_count'] ?? 0); + $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; + + return $model; } - /** - * MailingList constructor. - * - * @param string $name - * @param string $address - * @param string $accessLevel - * @param string $description - * @param int $membersCount - */ - private function __construct($name, $address, $accessLevel, $description, $membersCount, \DateTime $createdAt) + private function __construct() { - $this->name = $name; - $this->address = $address; - $this->accessLevel = $accessLevel; - $this->description = $description; - $this->membersCount = $membersCount; - $this->createdAt = $createdAt; } - /** - * @return string - */ - public function getName() + public function getName(): ?string { return $this->name; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): ?string { return $this->address; } - /** - * @return string - */ - public function getAccessLevel() + public function getAccessLevel(): ?string { return $this->accessLevel; } - /** - * @return string - */ - public function getDescription() + public function getDescription(): ?string { return $this->description; } - /** - * @return int - */ - public function getMembersCount() + public function getMembersCount(): int { return $this->membersCount; } - /** - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; } diff --git a/src/Model/MailingList/Member/CreateResponse.php b/src/Model/MailingList/Member/CreateResponse.php index 33dd4ef..bfff039 100644 --- a/src/Model/MailingList/Member/CreateResponse.php +++ b/src/Model/MailingList/Member/CreateResponse.php @@ -15,47 +15,28 @@ use Mailgun\Model\ApiResponse; final class CreateResponse implements ApiResponse { - /** - * @var Member - */ private $member; - - /** - * @var string - */ private $message; - public static function create(array $data) + public static function create(array $data): self { - $member = Member::create($data['member']); - $message = isset($data['message']) ? $data['message'] : ''; + $model = new self(); + $model->member = Member::create($data['member']); + $model->message = $data['message'] ?? ''; - return new self($member, $message); + return $model; } - /** - * CreateMemberResponse constructor. - * - * @param string $message - */ - private function __construct(Member $member, $message) + private function __construct() { - $this->member = $member; - $this->message = $message; } - /** - * @return Member - */ - public function getMember() + public function getMember(): Member { return $this->member; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } diff --git a/src/Model/MailingList/Member/DeleteResponse.php b/src/Model/MailingList/Member/DeleteResponse.php index 8acd17c..44ac252 100644 --- a/src/Model/MailingList/Member/DeleteResponse.php +++ b/src/Model/MailingList/Member/DeleteResponse.php @@ -15,47 +15,28 @@ use Mailgun\Model\ApiResponse; final class DeleteResponse implements ApiResponse { - /** - * @var Member - */ private $member; - - /** - * @var string - */ private $message; - public static function create(array $data) + public static function create(array $data): self { - $member = Member::create($data['member']); - $message = isset($data['message']) ? $data['message'] : ''; + $model = new self(); + $model->member = Member::create($data['member']); + $model->message = $data['message'] ?? ''; - return new self($member, $message); + return $model; } - /** - * DeleteMemberResponse constructor. - * - * @param string $message - */ - private function __construct(Member $member, $message) + private function __construct() { - $this->member = $member; - $this->message = $message; } - /** - * @return Member - */ - public function getMember() + public function getMember(): Member { return $this->member; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } diff --git a/src/Model/MailingList/Member/IndexResponse.php b/src/Model/MailingList/Member/IndexResponse.php index e3377fe..b3c9842 100644 --- a/src/Model/MailingList/Member/IndexResponse.php +++ b/src/Model/MailingList/Member/IndexResponse.php @@ -24,10 +24,7 @@ final class IndexResponse implements ApiResponse, PagingProvider */ private $items; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { $items = []; @@ -37,22 +34,21 @@ final class IndexResponse implements ApiResponse, PagingProvider } } - return new self($items, $data['paging']); + $model = new self(); + $model->items = $items; + $model->paging = $data['paging']; + + return $model; } - /** - * @param Member[] $items - */ - private function __construct(array $items, array $paging) + private function __construct() { - $this->items = $items; - $this->paging = $paging; } /** * @return Member[] */ - public function getItems() + public function getItems(): array { return $this->items; } diff --git a/src/Model/MailingList/Member/Member.php b/src/Model/MailingList/Member/Member.php index fe6e9e7..1c7a035 100644 --- a/src/Model/MailingList/Member/Member.php +++ b/src/Model/MailingList/Member/Member.php @@ -15,75 +15,42 @@ use Mailgun\Model\ApiResponse; final class Member implements ApiResponse { - /** - * @var string - */ private $name; - - /** - * @var string - */ private $address; - - /** - * @var array - */ private $vars; - - /** - * @var bool - */ private $subscribed; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - return new self( - isset($data['name']) ? $data['name'] : null, - isset($data['address']) ? $data['address'] : null, - isset($data['vars']) ? $data['vars'] : [], - isset($data['subscribed']) ? (bool) $data['subscribed'] : null - ); + $model = new self(); + $model->name = $data['name'] ?? null; + $model->address = $data['address'] ?? null; + $model->vars = $data['vars'] ?? []; + $model->subscribed = $data['subscribed'] ?? null; + + return $model; } - private function __construct($name, $address, $vars = [], $subscribed = null) + private function __construct() { - $this->name = $name; - $this->address = $address; - $this->vars = $vars; - $this->subscribed = $subscribed; } - /** - * @return string - */ - public function getName() + public function getName(): ?string { return $this->name; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): ?string { return $this->address; } - /** - * @return array - */ - public function getVars() + public function getVars(): array { return $this->vars; } - /** - * @return bool - */ - public function isSubscribed() + public function isSubscribed(): ?bool { return $this->subscribed; } diff --git a/src/Model/MailingList/Member/ShowResponse.php b/src/Model/MailingList/Member/ShowResponse.php index b65fc69..3ca8534 100644 --- a/src/Model/MailingList/Member/ShowResponse.php +++ b/src/Model/MailingList/Member/ShowResponse.php @@ -15,27 +15,21 @@ use Mailgun\Model\ApiResponse; final class ShowResponse implements ApiResponse { - /** - * @var Member - */ private $member; - public static function create(array $data) + public static function create(array $data): self { - $member = Member::create($data['member']); + $model = new self(); + $model->member = Member::create($data['member']); - return new self($member); + return $model; } - private function __construct(Member $member) + private function __construct() { - $this->member = $member; } - /** - * @return Member - */ - public function getMember() + public function getMember(): Member { return $this->member; } diff --git a/src/Model/MailingList/Member/UpdateResponse.php b/src/Model/MailingList/Member/UpdateResponse.php index e017caf..dd17011 100644 --- a/src/Model/MailingList/Member/UpdateResponse.php +++ b/src/Model/MailingList/Member/UpdateResponse.php @@ -15,47 +15,28 @@ use Mailgun\Model\ApiResponse; final class UpdateResponse implements ApiResponse { - /** - * @var Member - */ private $member; - - /** - * @var string - */ private $message; - public static function create(array $data) + public static function create(array $data): self { - $member = Member::create($data['member']); - $message = isset($data['message']) ? $data['message'] : ''; + $model = new self(); + $model->member = Member::create($data['member']); + $model->message = $data['message'] ?? ''; - return new self($member, $message); + return $model; } - /** - * UpdateMemberResponse constructor. - * - * @param string $message - */ - private function __construct(Member $member, $message) + private function __construct() { - $this->member = $member; - $this->message = $message; } - /** - * @return Member - */ - public function getMember() + public function getMember(): Member { return $this->member; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } diff --git a/src/Model/MailingList/PagesResponse.php b/src/Model/MailingList/PagesResponse.php index a0e605f..78745c9 100644 --- a/src/Model/MailingList/PagesResponse.php +++ b/src/Model/MailingList/PagesResponse.php @@ -19,9 +19,6 @@ final class PagesResponse implements ApiResponse, PagingProvider { use PaginationResponse; - /** - * @var MailingList[] - */ private $items; /** @@ -37,22 +34,21 @@ final class PagesResponse implements ApiResponse, PagingProvider } } - return new self($items, $data['paging']); + $model = new self(); + $model->items = $items; + $model->paging = $data['paging']; + + return $model; } - /** - * @param MailingList[] $items - */ - private function __construct(array $items, array $paging) + private function __construct() { - $this->items = $items; - $this->paging = $paging; } /** * @return MailingList[] */ - public function getLists() + public function getLists(): array { return $this->items; } diff --git a/src/Model/MailingList/ShowResponse.php b/src/Model/MailingList/ShowResponse.php index 922cefe..5280a38 100644 --- a/src/Model/MailingList/ShowResponse.php +++ b/src/Model/MailingList/ShowResponse.php @@ -15,27 +15,21 @@ use Mailgun\Model\ApiResponse; final class ShowResponse implements ApiResponse { - /** - * @var MailingList - */ private $list; - public static function create(array $data) + public static function create(array $data): self { - $list = MailingList::create($data['list']); + $model = new self(); + $model->list = MailingList::create($data['list']); - return new self($list); + return $model; } - private function __construct(MailingList $list) + private function __construct() { - $this->list = $list; } - /** - * @return MailingList - */ - public function getList() + public function getList(): MailingList { return $this->list; } diff --git a/src/Model/MailingList/UpdateResponse.php b/src/Model/MailingList/UpdateResponse.php index e30d0e6..f7a29ba 100644 --- a/src/Model/MailingList/UpdateResponse.php +++ b/src/Model/MailingList/UpdateResponse.php @@ -15,45 +15,28 @@ use Mailgun\Model\ApiResponse; final class UpdateResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var MailingList - */ private $list; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - $message = isset($data['message']) ? $data['message'] : ''; - $list = MailingList::create($data['list']); + $model = new self(); + $model->list = MailingList::create($data['list']); + $model->message = $data['message'] ?? ''; - return new self($list, $message); + return $model; } - private function __construct(MailingList $list, $message) + private function __construct() { - $this->list = $list; - $this->message = $message; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } - /** - * @return MailingList - */ - public function getList() + public function getList(): MailingList { return $this->list; } diff --git a/src/Model/Message/SendResponse.php b/src/Model/Message/SendResponse.php index a8cc147..f729a68 100644 --- a/src/Model/Message/SendResponse.php +++ b/src/Model/Message/SendResponse.php @@ -18,56 +18,28 @@ use Mailgun\Model\ApiResponse; */ final class SendResponse implements ApiResponse { - /** - * @var string - */ private $id; - - /** - * @var string - */ private $message; - /** - * @param string $id - * @param string $message - */ - private function __construct($id, $message) + private function __construct() { - $this->id = $id; - $this->message = $message; } - /** - * @return SendResponse - */ - public static function create(array $data) + public static function create(array $data): self { - $id = ''; - $message = ''; + $model = new self(); + $model->id = $data['id'] ?? ''; + $model->message = $data['message'] ?? ''; - if (isset($data['id'])) { - $id = $data['id']; - } - if (isset($data['message'])) { - $message = $data['message']; - } - - return new self($id, $message); + return $model; } - /** - * @return string - */ - public function getId() + public function getId(): string { return $this->id; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } diff --git a/src/Model/Message/ShowResponse.php b/src/Model/Message/ShowResponse.php index feee5bb..52451c4 100644 --- a/src/Model/Message/ShowResponse.php +++ b/src/Model/Message/ShowResponse.php @@ -18,382 +18,126 @@ use Mailgun\Model\ApiResponse; */ final class ShowResponse implements ApiResponse { - /** - * Only available with message/rfc2822. - * - * @var string - */ private $recipient; - - /** - * Only available with message/rfc2822. - * - * @var string - */ private $bodyMime; - - /** - * @var string - */ private $recipients; - - /** - * @var string - */ private $sender; - - /** - * @var string - */ private $from; - - /** - * @var string - */ private $subject; - - /** - * @var string - */ private $bodyPlain; - - /** - * @var string - */ private $strippedText; - - /** - * @var string - */ private $strippedSignature; - - /** - * @var string - */ private $bodyHtml; - - /** - * @var string - */ private $strippedHtml; - - /** - * @var array - */ private $attachments; - - /** - * @var string - */ private $messageUrl; - - /** - * @var string - */ private $contentIdMap; - - /** - * @var array - */ private $messageHeaders; - /** - * Do not let this object be creted without the ::create. - */ private function __construct() { } - /** - * @return ShowResponse - */ - public static function create(array $data) + public static function create(array $data): array { - $response = new self(); + $model = new self(); + $model->recipients = $data['recipients'] ?? null; + $model->sender = $data['sender'] ?? null; + $model->from = $data['from'] ?? null; + $model->subject = $data['subject'] ?? null; + $model->bodyPlain = $data['body-plain'] ?? null; + $model->strippedText = $data['stripped-text'] ?? null; + $model->strippedSignature = $data['stripped-signature'] ?? null; + $model->bodyHtml = $data['body-html'] ?? null; + $model->strippedHtml = $data['stripped-html'] ?? null; + $model->messageUrl = $data['message-url'] ?? null; + $model->messageHeaders = $data['message-headers'] ?? null; + $model->recipient = $data['recipient'] ?? null; + $model->bodyMime = $data['body-mime'] ?? null; + $model->attachments = $data['attachments'] ?? []; + $model->contentIdMap = $data['content-id-map'] ?? null; - if (isset($data['recipients'])) { - $response->setRecipients($data['recipients']); - } - if (isset($data['sender'])) { - $response->setSender($data['sender']); - } - if (isset($data['from'])) { - $response->setFrom($data['from']); - } - if (isset($data['subject'])) { - $response->setSubject($data['subject']); - } - if (isset($data['body-plain'])) { - $response->setBodyPlain($data['body-plain']); - } - if (isset($data['stripped-text'])) { - $response->setStrippedText($data['stripped-text']); - } - if (isset($data['stripped-signature'])) { - $response->setStrippedSignature($data['stripped-signature']); - } - if (isset($data['body-html'])) { - $response->setBodyHtml($data['body-html']); - } - if (isset($data['stripped-html'])) { - $response->setStrippedHtml($data['stripped-html']); - } - if (isset($data['message-url'])) { - $response->setMessageUrl($data['message-url']); - } - if (isset($data['message-headers'])) { - $response->setMessageHeaders($data['message-headers']); - } - if (isset($data['recipient'])) { - $response->setRecipient($data['recipient']); - } - if (isset($data['body-mime'])) { - $response->setBodyMime($data['body-mime']); - } - if (isset($data['attachments'])) { - $response->setAttachments($data['attachments']); - } - if (isset($data['content-id-map'])) { - $response->setContentIdMap($data['content-id-map']); - } - - return $response; + return $model; } /** - * @return string + * Only available with message/rfc2822. */ - public function getRecipient() + public function getRecipient(): ?string { return $this->recipient; } /** - * @param string $recipient + * Only available with message/rfc2822. */ - private function setRecipient($recipient) - { - $this->recipient = $recipient; - } - - /** - * @return string - */ - public function getBodyMime() + public function getBodyMime(): ?string { return $this->bodyMime; } - /** - * @param string $bodyMime - */ - private function setBodyMime($bodyMime) - { - $this->bodyMime = $bodyMime; - } - - /** - * @return string - */ - public function getRecipients() + public function getRecipients(): ?string { return $this->recipients; } - /** - * @param string $recipients - */ - private function setRecipients($recipients) - { - $this->recipients = $recipients; - } - - /** - * @return string - */ - public function getSender() + public function getSender(): ?string { return $this->sender; } - /** - * @param string $sender - */ - private function setSender($sender) - { - $this->sender = $sender; - } - - /** - * @return string - */ - public function getFrom() + public function getFrom(): ?string { return $this->from; } - /** - * @param string $from - */ - private function setFrom($from) - { - $this->from = $from; - } - - /** - * @return string - */ - public function getSubject() + public function getSubject(): ?string { return $this->subject; } - /** - * @param string $subject - */ - private function setSubject($subject) - { - $this->subject = $subject; - } - - /** - * @return string - */ - public function getBodyPlain() + public function getBodyPlain(): ?string { return $this->bodyPlain; } - /** - * @param string $bodyPlain - */ - private function setBodyPlain($bodyPlain) - { - $this->bodyPlain = $bodyPlain; - } - - /** - * @return string - */ - public function getStrippedText() + public function getStrippedText(): ?string { return $this->strippedText; } - /** - * @param string $strippedText - */ - private function setStrippedText($strippedText) - { - $this->strippedText = $strippedText; - } - - /** - * @return string - */ - public function getStrippedSignature() + public function getStrippedSignature(): ?string { return $this->strippedSignature; } - /** - * @param string $strippedSignature - */ - private function setStrippedSignature($strippedSignature) - { - $this->strippedSignature = $strippedSignature; - } - - /** - * @return string - */ - public function getBodyHtml() + public function getBodyHtml(): ?string { return $this->bodyHtml; } - /** - * @param string $bodyHtml - */ - private function setBodyHtml($bodyHtml) - { - $this->bodyHtml = $bodyHtml; - } - - /** - * @return string - */ - public function getStrippedHtml() + public function getStrippedHtml(): ?string { return $this->strippedHtml; } - /** - * @param string $strippedHtml - */ - private function setStrippedHtml($strippedHtml) - { - $this->strippedHtml = $strippedHtml; - } - - /** - * @return array - */ - public function getAttachments() + public function getAttachments(): array { return $this->attachments; } - /** - * @param array $attachments - */ - private function setAttachments($attachments) - { - $this->attachments = $attachments; - } - - /** - * @return string - */ - public function getMessageUrl() + public function getMessageUrl(): ?string { return $this->messageUrl; } - /** - * @param string $messageUrl - */ - private function setMessageUrl($messageUrl) - { - $this->messageUrl = $messageUrl; - } - - /** - * @return string - */ - public function getContentIdMap() + public function getContentIdMap(): ?string { return $this->contentIdMap; } - /** - * @param string $contentIdMap - */ - public function setContentIdMap($contentIdMap) - { - $this->contentIdMap = $contentIdMap; - } - - /** - * @return array - */ - public function getMessageHeaders() + public function getMessageHeaders(): array { return $this->messageHeaders; } - - private function setMessageHeaders(array $messageHeaders) - { - $this->messageHeaders = $messageHeaders; - } } diff --git a/src/Model/Route/Action.php b/src/Model/Route/Action.php index 134ec63..3cced6a 100644 --- a/src/Model/Route/Action.php +++ b/src/Model/Route/Action.php @@ -16,9 +16,6 @@ namespace Mailgun\Model\Route; */ final class Action { - /** - * @var string - */ private $action; /** @@ -42,10 +39,7 @@ final class Action $this->action = $action; } - /** - * @return string - */ - public function getAction() + public function getAction(): string { return $this->action; } diff --git a/src/Model/Route/CreateResponse.php b/src/Model/Route/CreateResponse.php index 99a2d20..7b7c1f0 100644 --- a/src/Model/Route/CreateResponse.php +++ b/src/Model/Route/CreateResponse.php @@ -18,50 +18,28 @@ use Mailgun\Model\ApiResponse; */ final class CreateResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var Route - */ private $route; - /** - * {@inheritdoc} - */ - public static function create(array $data) + public static function create(array $data): self { - $message = isset($data['message']) ? $data['message'] : null; - $route = isset($data['route']) ? Route::create($data['route']) : null; + $model = new self(); + $model->message = $data['message'] ?? null; + $model->route = isset($data['id']) ? Route::create($data) : null; - return new self($message, $route); + return $model; } - /** - * CreateResponse Private Constructor. - * - * @param string|null $message - */ - private function __construct($message = null, Route $route = null) + private function __construct() { - $this->message = $message; - $this->route = $route; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } - /** - * @return Route - */ - public function getRoute() + public function getRoute(): ?Route { return $this->route; } diff --git a/src/Model/Route/DeleteResponse.php b/src/Model/Route/DeleteResponse.php index 5b4e3a3..b9575cd 100644 --- a/src/Model/Route/DeleteResponse.php +++ b/src/Model/Route/DeleteResponse.php @@ -18,49 +18,28 @@ use Mailgun\Model\ApiResponse; */ final class DeleteResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var string - */ private $error; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - return new self( - isset($data['message']) ? $data['message'] : null, - isset($data['error']) ? $data['error'] : null - ); + $model = new self(); + $model->message = $data['message'] ?? null; + $model->error = $data['error'] ?? null; + + return $model; } - /** - * @param string $message - * @param string $error - */ - private function __construct($message, $error) + private function __construct() { - $this->message = $message; - $this->error = $error; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } - /** - * @return string - */ - public function getError() + public function getError(): ?string { return $this->error; } diff --git a/src/Model/Route/IndexResponse.php b/src/Model/Route/IndexResponse.php index dc12eed..5bdf170 100644 --- a/src/Model/Route/IndexResponse.php +++ b/src/Model/Route/IndexResponse.php @@ -18,20 +18,10 @@ use Mailgun\Model\ApiResponse; */ final class IndexResponse implements ApiResponse { - /** - * @var int - */ private $totalCount; - - /** - * @var Route[] - */ private $items; - /** - * {@inheritdoc} - */ - public static function create(array $data) + public static function create(array $data): self { $items = []; @@ -41,29 +31,18 @@ final class IndexResponse implements ApiResponse } } - if (isset($data['total_count'])) { - $count = $data['total_count']; - } else { - $count = count($items); - } + $model = new self(); + $model->items = $items; + $model->totalCount = (int) ($data['total_count'] ?? count($items)); - return new self($count, $items); + return $model; } - /** - * @param int $totalCount - * @param Route[] $items - */ - private function __construct($totalCount, array $items) + private function __construct() { - $this->totalCount = $totalCount; - $this->items = $items; } - /** - * @return int - */ - public function getTotalCount() + public function getTotalCount(): int { return $this->totalCount; } @@ -71,7 +50,7 @@ final class IndexResponse implements ApiResponse /** * @return Route[] */ - public function getRoutes() + public function getRoutes(): array { return $this->items; } diff --git a/src/Model/Route/Route.php b/src/Model/Route/Route.php index ff945f4..5679712 100644 --- a/src/Model/Route/Route.php +++ b/src/Model/Route/Route.php @@ -16,78 +16,31 @@ namespace Mailgun\Model\Route; */ final class Route { - /** - * @var string - */ private $id; - - /** - * @var int - */ private $priority; - - /** - * @var string - */ private $filter; - - /** - * @var Action[] - */ private $actions; - - /** - * @var string - */ private $description; - - /** - * @var \DateTime - */ private $createdAt; - /** - * Route Named Constructor. - * - * - * @return Route - */ - public static function create(array $data) + public static function create(array $data): self { - return new self( - isset($data['id']) ? $data['id'] : null, - isset($data['priority']) ? $data['priority'] : null, - isset($data['expression']) ? $data['expression'] : null, - isset($data['actions']) ? $data['actions'] : [], - isset($data['description']) ? $data['description'] : null, - isset($data['created_at']) ? new \DateTime($data['created_at']) : null - ); + $model = new self(); + $model->id = $data['id'] ?? null; + $model->priority = $data['priority'] ?? null; + $model->filter = $data['expression'] ?? null; + $model->actions = Action::createMultiple($data['actions'] ?? []); + $model->description = $data['description'] ?? null; + $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; + + return $model; } - /** - * Route Private Constructor. - * - * @param string $id - * @param int $priority - * @param string $expression - * @param array $actions - * @param string $description - * @param \DateTime $createdAt - */ - private function __construct($id, $priority, $expression, $actions, $description, \DateTime $createdAt = null) + private function __construct() { - $this->id = $id; - $this->priority = $priority; - $this->filter = $expression; - $this->actions = Action::createMultiple($actions); - $this->description = $description; - $this->createdAt = $createdAt; } - /** - * @return string - */ - public function getId() + public function getId(): ?string { return $this->id; } @@ -95,39 +48,27 @@ final class Route /** * @return Action[] */ - public function getActions() + public function getActions(): array { return $this->actions; } - /** - * @return string - */ - public function getDescription() + public function getDescription(): ?string { return $this->description; } - /** - * @return string - */ - public function getFilter() + public function getFilter(): ?string { return $this->filter; } - /** - * @return int - */ - public function getPriority() + public function getPriority(): ?int { return $this->priority; } - /** - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; } diff --git a/src/Model/Route/ShowResponse.php b/src/Model/Route/ShowResponse.php index 4d7a9d7..9fd0334 100644 --- a/src/Model/Route/ShowResponse.php +++ b/src/Model/Route/ShowResponse.php @@ -18,35 +18,21 @@ use Mailgun\Model\ApiResponse; */ final class ShowResponse implements ApiResponse { - /** - * @var Route|null - */ private $route; - /** - * {@inheritdoc} - */ - public static function create(array $data) + public static function create(array $data): self { - if (isset($data['route'])) { - return new self(Route::create($data['route'])); - } + $model = new self(); + $model->route = isset($data['route']) ? Route::create($data['route']) : null; - return new self(); + return $model; } - /** - * ShowResponse constructor. - */ - private function __construct(Route $route = null) + private function __construct() { - $this->route = $route; } - /** - * @return Route|null - */ - public function getRoute() + public function getRoute(): ?Route { return $this->route; } diff --git a/src/Model/Route/UpdateResponse.php b/src/Model/Route/UpdateResponse.php index 041a28b..876e42f 100644 --- a/src/Model/Route/UpdateResponse.php +++ b/src/Model/Route/UpdateResponse.php @@ -18,48 +18,28 @@ use Mailgun\Model\ApiResponse; */ final class UpdateResponse implements ApiResponse { - /** - * @var string|null - */ private $message; - - /** - * @var Route|null - */ private $route; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - $message = isset($data['message']) ? $data['message'] : null; - $route = isset($data['id']) ? Route::create($data) : null; + $model = new self(); + $model->message = $data['message'] ?? null; + $model->route = isset($data['id']) ? Route::create($data) : null; - return new self($message, $route); + return $model; } - /** - * @param string|null $message - */ - private function __construct($message = null, Route $route = null) + private function __construct() { - $this->message = $message; - $this->route = $route; } - /** - * @return string|null - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } - /** - * @return Route|null - */ - public function getRoute() + public function getRoute(): ?Route { return $this->route; }