Fixed PHP7 on Event model and Ip model

This commit is contained in:
Nyholm 2019-01-16 19:04:29 +01:00 committed by David Garcia
parent 51cff9dbdc
commit 28a4454c63
5 changed files with 76 additions and 420 deletions

View File

@ -16,217 +16,79 @@ namespace Mailgun\Model\Event;
*/ */
final class Event final class Event
{ {
/**
* @var string status
*/
private $event; private $event;
/**
* @var string
*/
private $id; private $id;
/**
* @var float
*/
private $timestamp; private $timestamp;
/**
* A \DateTime representation of $timestamp.
*
* @var \DateTime
*/
private $eventDate; private $eventDate;
private $tags;
/**
* @var string[]
*/
private $tags = [];
/**
* @var string
*/
private $url; private $url;
/**
* @var string
*/
private $severity; private $severity;
private $envelope;
/**
* @var array
*/
private $envelope = [];
/**
* @var array
*/
private $deliveryStatus; private $deliveryStatus;
private $campaigns;
/**
* @var string[]
*/
private $campaigns = [];
/**
* @var string
*/
private $ip; private $ip;
private $clientInfo;
/**
* @var array
*/
private $clientInfo = [];
/**
* @var string
*/
private $reason; private $reason;
private $userVariables;
/** private $flags;
* @var array private $routes;
*/ private $message;
private $userVariables = [];
/**
* @var array key=>bool
*/
private $flags = [];
/**
* @var array multi dimensions
*/
private $routes = [];
/**
* @var array multi dimensions
*/
private $message = [];
/**
* @var string
*/
private $recipient; private $recipient;
private $geolocation;
/** private $storage;
* @var array
*/
private $geolocation = [];
/**
* @var array
*/
private $storage = [];
/**
* @var string
*/
private $method; private $method;
/** private function __construct()
* @param string $event
* @param string $id
* @param float $timestamp
*/
private function __construct($event, $id, $timestamp)
{ {
$this->event = $event;
$this->id = $id;
$this->timestamp = $timestamp;
$this->eventDate = new \DateTime();
$this->eventDate->setTimestamp((int) $timestamp);
} }
/** public static function create(array $data): self
* @return Event
*/
public static function create(array $data)
{ {
$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'])) { return $model;
$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;
} }
/** public function getEvent(): string
* @return string
*/
public function getEvent()
{ {
return $this->event; return $this->event;
} }
/** public function getId(): string
* @return string
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function getTimestamp(): int
* @return float
*/
public function getTimestamp()
{ {
return $this->timestamp; return $this->timestamp;
} }
/** /**
* @return \DateTime * A \DateTimeImmutable representation of $timestamp.
*/ */
public function getEventDate() public function getEventDate(): \DateTimeImmutable
{ {
return $this->eventDate; return $this->eventDate;
} }
@ -234,272 +96,100 @@ final class Event
/** /**
* @return string[] * @return string[]
*/ */
public function getTags() public function getTags(): array
{ {
return $this->tags; return $this->tags;
} }
/** public function getUrl(): string
* @param string[] $tags
*/
private function setTags($tags)
{
$this->tags = $tags;
}
/**
* @return string
*/
public function getUrl()
{ {
return $this->url; return $this->url;
} }
/** public function getSeverity(): string
* @param string $url
*/
private function setUrl($url)
{ {
$this->url = $url; return $this->severity;
} }
/** public function getEnvelope(): array
* @return array
*/
public function getEnvelope()
{ {
return $this->envelope; return $this->envelope;
} }
/** public function getDeliveryStatus(): array
* @param array $envelope
*/
private function setEnvelope($envelope)
{
$this->envelope = $envelope;
}
/**
* @return array
*/
public function getDeliveryStatus()
{ {
return $this->deliveryStatus; return $this->deliveryStatus;
} }
/**
* @param array $deliveryStatus
*/
private function setDeliveryStatus($deliveryStatus)
{
$this->deliveryStatus = $deliveryStatus;
}
/** /**
* @return string[] * @return string[]
*/ */
public function getCampaigns() public function getCampaigns(): array
{ {
return $this->campaigns; return $this->campaigns;
} }
/** public function getIp(): string
* @param string[] $campaigns
*/
private function setCampaigns($campaigns)
{
$this->campaigns = $campaigns;
}
/**
* @return string
*/
public function getIp()
{ {
return $this->ip; return $this->ip;
} }
/** public function getClientInfo(): array
* @param string $ip
*/
private function setIp($ip)
{
$this->ip = $ip;
}
/**
* @return array
*/
public function getClientInfo()
{ {
return $this->clientInfo; return $this->clientInfo;
} }
/** public function getReason(): string
* @param array $clientInfo
*/
private function setClientInfo($clientInfo)
{
$this->clientInfo = $clientInfo;
}
/**
* @return string
*/
public function getReason()
{ {
return $this->reason; return $this->reason;
} }
/** public function getUserVariables(): array
* @param string $reason
*/
private function setReason($reason)
{
$this->reason = $reason;
}
/**
* @return array
*/
public function getUserVariables()
{ {
return $this->userVariables; return $this->userVariables;
} }
/** /**
* @param array $userVariables * key=>bool.
*/ */
private function setUserVariables($userVariables) public function getFlags(): array
{
$this->userVariables = $userVariables;
}
/**
* @return array
*/
public function getFlags()
{ {
return $this->flags; return $this->flags;
} }
/** /**
* @param array $flags * multi dimensions.
*/ */
private function setFlags($flags) public function getRoutes(): array
{
$this->flags = $flags;
}
/**
* @return array
*/
public function getRoutes()
{ {
return $this->routes; return $this->routes;
} }
/** /**
* @param array $routes * multi dimensions.
*/ */
private function setRoutes($routes) public function getMessage(): array
{
$this->routes = $routes;
}
/**
* @return array
*/
public function getMessage()
{ {
return $this->message; return $this->message;
} }
/** public function getRecipient(): string
* @param array $message
*/
private function setMessage($message)
{
$this->message = $message;
}
/**
* @return string
*/
public function getRecipient()
{ {
return $this->recipient; return $this->recipient;
} }
/** public function getGeolocation(): array
* @param string $recipient
*/
private function setRecipient($recipient)
{
$this->recipient = $recipient;
}
/**
* @return array
*/
public function getGeolocation()
{ {
return $this->geolocation; return $this->geolocation;
} }
/** public function getStorage(): array
* @param array $geolocation
*/
private function setGeolocation($geolocation)
{
$this->geolocation = $geolocation;
}
/**
* @return array
*/
public function getStorage()
{ {
return $this->storage; return $this->storage;
} }
/** public function getMethod(): string
* @param array $storage
*/
private function setStorage($storage)
{
$this->storage = $storage;
}
/**
* @return string
*/
public function getMethod()
{ {
return $this->method; 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;
}
} }

View File

@ -21,19 +21,10 @@ use Mailgun\Model\ApiResponse;
final class EventResponse implements ApiResponse, PagingProvider final class EventResponse implements ApiResponse, PagingProvider
{ {
use PaginationResponse; use PaginationResponse;
/**
* @var Event[]
*/
private $items; private $items;
/** private function __construct()
* @param Event[] $items
*/
private function __construct(array $items, array $paging)
{ {
$this->items = $items;
$this->paging = $paging;
} }
public static function create(array $data) 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[] * @return Event[]
*/ */
public function getItems() public function getItems(): array
{ {
return $this->items; return $this->items;
} }

View File

@ -26,7 +26,7 @@ final class IndexResponse implements ApiResponse
/** /**
* @var int * @var int
*/ */
private $totalCount = 0; private $totalCount;
private function __construct() private function __construct()
{ {
@ -36,7 +36,7 @@ final class IndexResponse implements ApiResponse
{ {
$model = new self(); $model = new self();
$model->items = $data['items']; $model->items = $data['items'];
$model->totalCount = $data['total_count']; $model->totalCount = $data['total_count'] ?? 0;
return $model; return $model;
} }
@ -44,15 +44,12 @@ final class IndexResponse implements ApiResponse
/** /**
* @return string[] * @return string[]
*/ */
public function getItems() public function getItems(): array
{ {
return $this->items; return $this->items;
} }
/** public function getTotalCount(): int
* @return int
*/
public function getTotalCount()
{ {
return $this->totalCount; return $this->totalCount;
} }

View File

@ -18,19 +18,8 @@ use Mailgun\Model\ApiResponse;
*/ */
final class ShowResponse implements ApiResponse final class ShowResponse implements ApiResponse
{ {
/**
* @var string
*/
private $ip; private $ip;
/**
* @var bool
*/
private $dedicated; private $dedicated;
/**
* @var string
*/
private $rdns; private $rdns;
private function __construct() private function __construct()
@ -47,26 +36,17 @@ final class ShowResponse implements ApiResponse
return $model; return $model;
} }
/** public function getIp(): string
* @return string
*/
public function getIp()
{ {
return $this->ip; return $this->ip;
} }
/** public function getDedicated(): bool
* @return bool
*/
public function getDedicated()
{ {
return $this->dedicated; return $this->dedicated;
} }
/** public function getRdns(): string
* @return string
*/
public function getRdns()
{ {
return $this->rdns; return $this->rdns;
} }

View File

@ -18,9 +18,6 @@ use Mailgun\Model\ApiResponse;
*/ */
final class UpdateResponse implements ApiResponse final class UpdateResponse implements ApiResponse
{ {
/**
* @var string
*/
private $message; private $message;
private function __construct() private function __construct()
@ -35,10 +32,7 @@ final class UpdateResponse implements ApiResponse
return $model; return $model;
} }
/** public function getMessage(): string
* @return string
*/
public function getMessage()
{ {
return $this->message; return $this->message;
} }