diff --git a/src/Model/Suppression/BaseResponse.php b/src/Model/Suppression/BaseResponse.php index bc5516a..e97d2fb 100644 --- a/src/Model/Suppression/BaseResponse.php +++ b/src/Model/Suppression/BaseResponse.php @@ -20,49 +20,28 @@ use Mailgun\Model\ApiResponse; */ abstract class BaseResponse implements ApiResponse { - /** - * @var string - */ private $address; - - /** - * @var string - */ private $message; - /** - * @param string $address - * @param string $message - */ - private function __construct($address, $message) + private function __construct() { - $this->address = $address; - $this->message = $message; } - /** - * @return BaseResponse - */ - public static function create(array $data) + public static function create(array $data): self { - $address = isset($data['address']) ? $data['address'] : ''; - $message = isset($data['message']) ? $data['message'] : ''; + $model = new static(); + $model->address = $data['address'] ?? ''; + $model->message = $data['message'] ?? ''; - return new static($address, $message); + return $model; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): string { return $this->address; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): string { return $this->message; } diff --git a/src/Model/Suppression/Bounce/Bounce.php b/src/Model/Suppression/Bounce/Bounce.php index 77a8a4d..35f4107 100644 --- a/src/Model/Suppression/Bounce/Bounce.php +++ b/src/Model/Suppression/Bounce/Bounce.php @@ -16,105 +16,44 @@ namespace Mailgun\Model\Suppression\Bounce; */ class Bounce { - /** - * @var string - */ private $address; - - /** - * @var string - */ private $code; - - /** - * @var string - */ private $error; - - /** - * @var \DateTime - */ private $createdAt; - /** - * @param string $address - */ - private function __construct($address) + private function __construct() { - $this->address = $address; - $this->createdAt = new \DateTime(); } - /** - * @return Bounce - */ - public static function create(array $data) + public static function create(array $data): self { - $bounce = new self($data['address']); + $model = new self(); - if (isset($data['code'])) { - $bounce->setCode($data['code']); - } - if (isset($data['error'])) { - $bounce->setError($data['error']); - } - if (isset($data['created_at'])) { - $bounce->setCreatedAt(new \DateTime($data['created_at'])); - } + $model->address = $data['address'] ?? null; + $model->code = $data['code'] ?? null; + $model->error = $data['error'] ?? null; + $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; - return $bounce; + return $model; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): ?string { return $this->address; } - /** - * @return string - */ - public function getCode() + public function getCode(): ?string { return $this->code; } - /** - * @param string $code - */ - private function setCode($code) - { - $this->code = $code; - } - - /** - * @return string - */ - public function getError() + public function getError(): ?string { return $this->error; } - /** - * @param string $error - */ - private function setError($error) - { - $this->error = $error; - } - - /** - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } - - private function setCreatedAt(\DateTime $createdAt) - { - $this->createdAt = $createdAt; - } } diff --git a/src/Model/Suppression/Bounce/IndexResponse.php b/src/Model/Suppression/Bounce/IndexResponse.php index 8ea1cf3..5eb1db5 100644 --- a/src/Model/Suppression/Bounce/IndexResponse.php +++ b/src/Model/Suppression/Bounce/IndexResponse.php @@ -22,24 +22,13 @@ final class IndexResponse implements ApiResponse, PagingProvider { use PaginationResponse; - /** - * @var Bounce[] - */ private $items; - /** - * @param Bounce[] $items - */ - private function __construct(array $items, array $paging) + private function __construct() { - $this->items = $items; - $this->paging = $paging; } - /** - * @return IndexResponse - */ - public static function create(array $data) + public static function create(array $data): self { $bounces = []; if (isset($data['items'])) { @@ -48,13 +37,18 @@ final class IndexResponse implements ApiResponse, PagingProvider } } - return new self($bounces, $data['paging']); + $model = new self(); + + $model->items = $bounces; + $model->paging = $data['paging']; + + return $model; } /** * @return Bounce[] */ - public function getItems() + public function getItems(): array { return $this->items; } diff --git a/src/Model/Suppression/Complaint/Complaint.php b/src/Model/Suppression/Complaint/Complaint.php index e3ca6d6..5e5d4f1 100644 --- a/src/Model/Suppression/Complaint/Complaint.php +++ b/src/Model/Suppression/Complaint/Complaint.php @@ -16,57 +16,30 @@ namespace Mailgun\Model\Suppression\Complaint; */ class Complaint { - /** - * @var string - */ private $address; - - /** - * @var \DateTime - */ private $createdAt; - /** - * @param string $address - */ - private function __construct($address) + private function __construct() { - $this->address = $address; - $this->createdAt = new \DateTime(); } - /** - * @return Complaint - */ - public static function create(array $data) + public static function create(array $data): self { - $complaint = new self($data['address']); + $model = new self(); - if (isset($data['created_at'])) { - $complaint->setCreatedAt(new \DateTime($data['created_at'])); - } + $model->address = $data['address'] ?? null; + $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; - return $complaint; + return $model; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): ?string { return $this->address; } - /** - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } - - private function setCreatedAt(\DateTime $createdAt) - { - $this->createdAt = $createdAt; - } } diff --git a/src/Model/Suppression/Complaint/IndexResponse.php b/src/Model/Suppression/Complaint/IndexResponse.php index 973e39b..9320b14 100644 --- a/src/Model/Suppression/Complaint/IndexResponse.php +++ b/src/Model/Suppression/Complaint/IndexResponse.php @@ -22,24 +22,13 @@ final class IndexResponse implements ApiResponse, PagingProvider { use PaginationResponse; - /** - * @var Complaint[] - */ private $items; - /** - * @param Complaint[] $items - */ - private function __construct(array $items, array $paging) + private function __construct() { - $this->items = $items; - $this->paging = $paging; } - /** - * @return IndexResponse - */ - public static function create(array $data) + public static function create(array $data): self { $complaints = []; if (isset($data['items'])) { @@ -48,13 +37,18 @@ final class IndexResponse implements ApiResponse, PagingProvider } } - return new self($complaints, $data['paging']); + $model = new self(); + + $model->items = $complaints; + $model->paging = $data['paging']; + + return $model; } /** * @return Complaint[] */ - public function getItems() + public function getItems(): array { return $this->items; } diff --git a/src/Model/Suppression/Unsubscribe/IndexResponse.php b/src/Model/Suppression/Unsubscribe/IndexResponse.php index e257b2f..683bd5d 100644 --- a/src/Model/Suppression/Unsubscribe/IndexResponse.php +++ b/src/Model/Suppression/Unsubscribe/IndexResponse.php @@ -41,24 +41,11 @@ final class IndexResponse implements ApiResponse, PagingProvider */ private $totalCount; - /** - * @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe - * - * @param Unsubscribe[] $items - */ - private function __construct(array $items, array $paging) + private function __construct() { - $this->items = $items; - $this->paging = $paging; } - /** - * Allow create the unsubscribe items with paging. - * - * - * @return IndexResponse - */ - public static function create(array $data) + public static function create(array $data): self { $unsubscribes = []; if (isset($data['items'])) { @@ -67,29 +54,23 @@ final class IndexResponse implements ApiResponse, PagingProvider } } - return new self($unsubscribes, $data['paging']); + $model = new self(); + + $model->items = $unsubscribes; + $model->paging = $data['paging']; + + return $model; } /** - * Get the Unsusbscribe item models from the response. - * - * @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe - * * @return Unsubscribe[] */ - public function getItems() + public function getItems(): array { return $this->items; } - /** - * Get the total count of Unsusbscribe in index response. - * - * @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe - * - * @return int - */ - public function getTotalCount() + public function getTotalCount(): int { if (null === $this->totalCount) { $this->totalCount = count($this->items); diff --git a/src/Model/Suppression/Unsubscribe/Unsubscribe.php b/src/Model/Suppression/Unsubscribe/Unsubscribe.php index 44195fe..0cbc4e7 100644 --- a/src/Model/Suppression/Unsubscribe/Unsubscribe.php +++ b/src/Model/Suppression/Unsubscribe/Unsubscribe.php @@ -16,80 +16,39 @@ namespace Mailgun\Model\Suppression\Unsubscribe; */ class Unsubscribe { - /** - * @var string - */ private $address; - - /** - * @var \DateTime - */ private $createdAt; - - /** - * @var array - */ private $tags = []; - /** - * @param string $address - */ - private function __construct($address) + private function __construct() { - $this->address = $address; - $this->createdAt = new \DateTime(); } - /** - * @return Unsubscribe - */ - public static function create(array $data) + public static function create(array $data): self { - $unsubscribe = new self($data['address']); + $model = new self(); + + $model->address = $data['address'] ?? null; + $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; if (isset($data['tags'])) { - $unsubscribe->setTags($data['tags']); - } - if (isset($data['created_at'])) { - $unsubscribe->setCreatedAt(new \DateTime($data['created_at'])); + $model->tags = $data['tags']; } - return $unsubscribe; + return $model; } - /** - * @return string - */ - public function getAddress() + public function getAddress(): ?string { return $this->address; } - /** - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } - private function setCreatedAt(\DateTime $createdAt) - { - $this->createdAt = $createdAt; - } - - /** - * @param array $tags - */ - private function setTags($tags) - { - $this->tags = $tags; - } - - /** - * @return array - */ - public function getTags() + public function getTags(): array { return $this->tags; }