From 28a4454c63dd2ff4db54bdfc86ca199f8bd6564b Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 16 Jan 2019 19:04:29 +0100 Subject: [PATCH] Fixed PHP7 on Event model and Ip model --- src/Model/Event/Event.php | 432 +++++------------------------- src/Model/Event/EventResponse.php | 19 +- src/Model/Ip/IndexResponse.php | 11 +- src/Model/Ip/ShowResponse.php | 26 +- src/Model/Ip/UpdateResponse.php | 8 +- 5 files changed, 76 insertions(+), 420 deletions(-) diff --git a/src/Model/Event/Event.php b/src/Model/Event/Event.php index 5ce5bd0..41cd6dd 100644 --- a/src/Model/Event/Event.php +++ b/src/Model/Event/Event.php @@ -16,217 +16,79 @@ namespace Mailgun\Model\Event; */ final class Event { - /** - * @var string status - */ private $event; - - /** - * @var string - */ private $id; - - /** - * @var float - */ private $timestamp; - - /** - * A \DateTime representation of $timestamp. - * - * @var \DateTime - */ private $eventDate; - - /** - * @var string[] - */ - private $tags = []; - - /** - * @var string - */ + private $tags; private $url; - - /** - * @var string - */ private $severity; - - /** - * @var array - */ - private $envelope = []; - - /** - * @var array - */ + private $envelope; private $deliveryStatus; - - /** - * @var string[] - */ - private $campaigns = []; - - /** - * @var string - */ + private $campaigns; private $ip; - - /** - * @var array - */ - private $clientInfo = []; - - /** - * @var string - */ + private $clientInfo; private $reason; - - /** - * @var array - */ - private $userVariables = []; - - /** - * @var array key=>bool - */ - private $flags = []; - - /** - * @var array multi dimensions - */ - private $routes = []; - - /** - * @var array multi dimensions - */ - private $message = []; - - /** - * @var string - */ + private $userVariables; + private $flags; + private $routes; + private $message; private $recipient; - - /** - * @var array - */ - private $geolocation = []; - - /** - * @var array - */ - private $storage = []; - - /** - * @var string - */ + private $geolocation; + private $storage; private $method; - /** - * @param string $event - * @param string $id - * @param float $timestamp - */ - private function __construct($event, $id, $timestamp) + private function __construct() { - $this->event = $event; - $this->id = $id; - $this->timestamp = $timestamp; - $this->eventDate = new \DateTime(); - $this->eventDate->setTimestamp((int) $timestamp); } - /** - * @return Event - */ - public static function create(array $data) + public static function create(array $data): self { - $event = new self($data['event'], $data['id'], $data['timestamp']); + $model = new self(); + $model->event = $data['event']; + $model->id = $data['id']; + $model->timestamp = (int) $data['timestamp']; + $model->eventDate = (new \DateTimeImmutable())->setTimestamp((int) $data['timestamp']); + $model->tags = $data['tags'] ?? []; + $model->envelope = $data['envelope'] ?? []; + $model->campaigns = $data['campaigns'] ?? []; + $model->userVariables = $data['user-variables'] ?? []; + $model->flags = $data['flags'] ?? []; + $model->routes = $data['routes'] ?? []; + $model->message = $data['message'] ?? []; + $model->recipient = $data['recipient'] ?? ''; + $model->method = $data['method'] ?? ''; + $model->deliveryStatus = $data['delivery-status'] ?? []; + $model->severity = $data['severity'] ?? ''; + $model->reason = $data['reason'] ?? ''; + $model->geolocation = $data['geolocation'] ?? []; + $model->ip = $data['ip'] ?? ''; + $model->clientInfo = $data['client-info'] ?? []; + $model->url = $data['url'] ?? ''; + $model->storage = $data['storage'] ?? []; - if (isset($data['tags'])) { - $event->setTags($data['tags']); - } - if (isset($data['envelope'])) { - $event->setEnvelope($data['envelope']); - } - if (isset($data['campaigns'])) { - $event->setCampaigns($data['campaigns']); - } - if (isset($data['user-variables'])) { - $event->setUserVariables($data['user-variables']); - } - if (isset($data['flags'])) { - $event->setFlags($data['flags']); - } - if (isset($data['routes'])) { - $event->setRoutes($data['routes']); - } - if (isset($data['message'])) { - $event->setMessage($data['message']); - } - if (isset($data['recipient'])) { - $event->setRecipient($data['recipient']); - } - if (isset($data['method'])) { - $event->setMethod($data['method']); - } - if (isset($data['delivery-status'])) { - $event->setDeliveryStatus($data['delivery-status']); - } - if (isset($data['severity'])) { - $event->setSeverity($data['severity']); - } - if (isset($data['reason'])) { - $event->setReason($data['reason']); - } - if (isset($data['geolocation'])) { - $event->setGeolocation($data['geolocation']); - } - if (isset($data['ip'])) { - $event->setIp($data['ip']); - } - if (isset($data['client-info'])) { - $event->setClientInfo($data['client-info']); - } - if (isset($data['url'])) { - $event->setUrl($data['url']); - } - if (isset($data['storage'])) { - $event->setStorage($data['storage']); - } - - return $event; + return $model; } - /** - * @return string - */ - public function getEvent() + public function getEvent(): string { return $this->event; } - /** - * @return string - */ - public function getId() + public function getId(): string { return $this->id; } - /** - * @return float - */ - public function getTimestamp() + public function getTimestamp(): int { return $this->timestamp; } /** - * @return \DateTime + * A \DateTimeImmutable representation of $timestamp. */ - public function getEventDate() + public function getEventDate(): \DateTimeImmutable { return $this->eventDate; } @@ -234,272 +96,100 @@ final class Event /** * @return string[] */ - public function getTags() + public function getTags(): array { return $this->tags; } - /** - * @param string[] $tags - */ - private function setTags($tags) - { - $this->tags = $tags; - } - - /** - * @return string - */ - public function getUrl() + public function getUrl(): string { return $this->url; } - /** - * @param string $url - */ - private function setUrl($url) + public function getSeverity(): string { - $this->url = $url; + return $this->severity; } - /** - * @return array - */ - public function getEnvelope() + public function getEnvelope(): array { return $this->envelope; } - /** - * @param array $envelope - */ - private function setEnvelope($envelope) - { - $this->envelope = $envelope; - } - - /** - * @return array - */ - public function getDeliveryStatus() + public function getDeliveryStatus(): array { return $this->deliveryStatus; } - /** - * @param array $deliveryStatus - */ - private function setDeliveryStatus($deliveryStatus) - { - $this->deliveryStatus = $deliveryStatus; - } - /** * @return string[] */ - public function getCampaigns() + public function getCampaigns(): array { return $this->campaigns; } - /** - * @param string[] $campaigns - */ - private function setCampaigns($campaigns) - { - $this->campaigns = $campaigns; - } - - /** - * @return string - */ - public function getIp() + public function getIp(): string { return $this->ip; } - /** - * @param string $ip - */ - private function setIp($ip) - { - $this->ip = $ip; - } - - /** - * @return array - */ - public function getClientInfo() + public function getClientInfo(): array { return $this->clientInfo; } - /** - * @param array $clientInfo - */ - private function setClientInfo($clientInfo) - { - $this->clientInfo = $clientInfo; - } - - /** - * @return string - */ - public function getReason() + public function getReason(): string { return $this->reason; } - /** - * @param string $reason - */ - private function setReason($reason) - { - $this->reason = $reason; - } - - /** - * @return array - */ - public function getUserVariables() + public function getUserVariables(): array { return $this->userVariables; } /** - * @param array $userVariables + * key=>bool. */ - private function setUserVariables($userVariables) - { - $this->userVariables = $userVariables; - } - - /** - * @return array - */ - public function getFlags() + public function getFlags(): array { return $this->flags; } /** - * @param array $flags + * multi dimensions. */ - private function setFlags($flags) - { - $this->flags = $flags; - } - - /** - * @return array - */ - public function getRoutes() + public function getRoutes(): array { return $this->routes; } /** - * @param array $routes + * multi dimensions. */ - private function setRoutes($routes) - { - $this->routes = $routes; - } - - /** - * @return array - */ - public function getMessage() + public function getMessage(): array { return $this->message; } - /** - * @param array $message - */ - private function setMessage($message) - { - $this->message = $message; - } - - /** - * @return string - */ - public function getRecipient() + public function getRecipient(): string { return $this->recipient; } - /** - * @param string $recipient - */ - private function setRecipient($recipient) - { - $this->recipient = $recipient; - } - - /** - * @return array - */ - public function getGeolocation() + public function getGeolocation(): array { return $this->geolocation; } - /** - * @param array $geolocation - */ - private function setGeolocation($geolocation) - { - $this->geolocation = $geolocation; - } - - /** - * @return array - */ - public function getStorage() + public function getStorage(): array { return $this->storage; } - /** - * @param array $storage - */ - private function setStorage($storage) - { - $this->storage = $storage; - } - - /** - * @return string - */ - public function getMethod() + public function getMethod(): string { return $this->method; } - - /** - * @param string $method - */ - private function setMethod($method) - { - $this->method = $method; - } - - /** - * @return string - */ - public function getSeverity() - { - return $this->severity; - } - - /** - * @param string $severity - */ - private function setSeverity($severity) - { - $this->severity = $severity; - } } diff --git a/src/Model/Event/EventResponse.php b/src/Model/Event/EventResponse.php index 44c53d4..de02a3a 100644 --- a/src/Model/Event/EventResponse.php +++ b/src/Model/Event/EventResponse.php @@ -21,19 +21,10 @@ use Mailgun\Model\ApiResponse; final class EventResponse implements ApiResponse, PagingProvider { use PaginationResponse; - - /** - * @var Event[] - */ private $items; - /** - * @param Event[] $items - */ - private function __construct(array $items, array $paging) + private function __construct() { - $this->items = $items; - $this->paging = $paging; } public static function create(array $data) @@ -45,13 +36,17 @@ final class EventResponse implements ApiResponse, PagingProvider } } - return new self($events, $data['paging']); + $model = new self(); + $model->items = $events; + $model->paging = $data['paging']; + + return $model; } /** * @return Event[] */ - public function getItems() + public function getItems(): array { return $this->items; } diff --git a/src/Model/Ip/IndexResponse.php b/src/Model/Ip/IndexResponse.php index f72f14d..3d461bd 100644 --- a/src/Model/Ip/IndexResponse.php +++ b/src/Model/Ip/IndexResponse.php @@ -26,7 +26,7 @@ final class IndexResponse implements ApiResponse /** * @var int */ - private $totalCount = 0; + private $totalCount; private function __construct() { @@ -36,7 +36,7 @@ final class IndexResponse implements ApiResponse { $model = new self(); $model->items = $data['items']; - $model->totalCount = $data['total_count']; + $model->totalCount = $data['total_count'] ?? 0; return $model; } @@ -44,15 +44,12 @@ final class IndexResponse implements ApiResponse /** * @return string[] */ - public function getItems() + public function getItems(): array { return $this->items; } - /** - * @return int - */ - public function getTotalCount() + public function getTotalCount(): int { return $this->totalCount; } diff --git a/src/Model/Ip/ShowResponse.php b/src/Model/Ip/ShowResponse.php index e86e4ff..46b4de4 100644 --- a/src/Model/Ip/ShowResponse.php +++ b/src/Model/Ip/ShowResponse.php @@ -18,19 +18,8 @@ use Mailgun\Model\ApiResponse; */ final class ShowResponse implements ApiResponse { - /** - * @var string - */ private $ip; - - /** - * @var bool - */ private $dedicated; - - /** - * @var string - */ private $rdns; private function __construct() @@ -47,26 +36,17 @@ final class ShowResponse implements ApiResponse return $model; } - /** - * @return string - */ - public function getIp() + public function getIp(): string { return $this->ip; } - /** - * @return bool - */ - public function getDedicated() + public function getDedicated(): bool { return $this->dedicated; } - /** - * @return string - */ - public function getRdns() + public function getRdns(): string { return $this->rdns; } diff --git a/src/Model/Ip/UpdateResponse.php b/src/Model/Ip/UpdateResponse.php index 0f9c136..2258f27 100644 --- a/src/Model/Ip/UpdateResponse.php +++ b/src/Model/Ip/UpdateResponse.php @@ -18,9 +18,6 @@ use Mailgun\Model\ApiResponse; */ final class UpdateResponse implements ApiResponse { - /** - * @var string - */ private $message; private function __construct() @@ -35,10 +32,7 @@ final class UpdateResponse implements ApiResponse return $model; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; }