From 0c3b716cf264d254836645c5e77522e71749a546 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sun, 13 Jan 2019 20:53:27 +0100 Subject: [PATCH] Updated some models with PHP 7 code --- src/Model/ApiResponse.php | 3 - src/Model/Attachment/Attachment.php | 8 ++- src/Model/Domain/AbstractDomainResponse.php | 62 +++++-------------- src/Model/Domain/ConnectionResponse.php | 30 +++------ src/Model/Domain/CreateCredentialResponse.php | 24 +++---- src/Model/Domain/CredentialResponse.php | 35 +++-------- src/Model/Domain/CredentialResponseItem.php | 62 ++++--------------- src/Model/Domain/DeleteCredentialResponse.php | 52 ++++------------ src/Model/Domain/DeleteResponse.php | 39 +++--------- 9 files changed, 80 insertions(+), 235 deletions(-) diff --git a/src/Model/ApiResponse.php b/src/Model/ApiResponse.php index 82a86b5..04bf1c6 100644 --- a/src/Model/ApiResponse.php +++ b/src/Model/ApiResponse.php @@ -18,9 +18,6 @@ interface ApiResponse { /** * Create an API response object from the HTTP response from the API server. - * - * - * @return self */ public static function create(array $data); } diff --git a/src/Model/Attachment/Attachment.php b/src/Model/Attachment/Attachment.php index 85a9799..d519215 100644 --- a/src/Model/Attachment/Attachment.php +++ b/src/Model/Attachment/Attachment.php @@ -20,7 +20,11 @@ final class Attachment implements ApiResponse { private $data; - public static function create(array $data) + private function __construct() + { + } + + public static function create(array $data): self { $new = new self(); $new->data = $data; @@ -28,7 +32,7 @@ final class Attachment implements ApiResponse return $new; } - public function getData() + public function getData(): array { return $this->data; } diff --git a/src/Model/Domain/AbstractDomainResponse.php b/src/Model/Domain/AbstractDomainResponse.php index 5078b19..c3fcba3 100644 --- a/src/Model/Domain/AbstractDomainResponse.php +++ b/src/Model/Domain/AbstractDomainResponse.php @@ -18,44 +18,21 @@ use Mailgun\Model\ApiResponse; */ abstract class AbstractDomainResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var Domain - */ private $domain; - - /** - * @var DnsRecord[] - */ private $inboundDnsRecords; - - /** - * @var DnsRecord[] - */ private $outboundDnsRecords; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { $rx = []; $tx = []; $domain = null; - $message = null; if (isset($data['domain'])) { $domain = Domain::create($data['domain']); } - if (isset($data['message'])) { - $message = $data['message']; - } - if (isset($data['receiving_dns_records'])) { foreach ($data['receiving_dns_records'] as $item) { $rx[] = DnsRecord::create($item); @@ -68,50 +45,41 @@ abstract class AbstractDomainResponse implements ApiResponse } } - return new static($domain, $rx, $tx, $message); + $model = new static(); + $model->domain = $domain; + $model->inboundDnsRecords = $rx; + $model->outboundDnsRecords = $tx; + $model->message = $data['message'] ?? null; + + return $model; } - /** - * @param DnsRecord[] $rxRecords - * @param DnsRecord[] $txRecords - * @param string $message - */ - private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords, $message) + private function __construct() { - $this->domain = $domainInfo; - $this->inboundDnsRecords = $rxRecords; - $this->outboundDnsRecords = $txRecords; - $this->message = $message; } - /** - * @return Domain - */ - public function getDomain() + public function getDomain(): ?Domain { return $this->domain; } /** - * @return DnsRecord[] + * @return DnsRecord[] tx */ - public function getInboundDNSRecords() + public function getInboundDNSRecords(): array { return $this->inboundDnsRecords; } /** - * @return DnsRecord[] + * @return DnsRecord[] tx */ - public function getOutboundDNSRecords() + public function getOutboundDNSRecords(): array { return $this->outboundDnsRecords; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } diff --git a/src/Model/Domain/ConnectionResponse.php b/src/Model/Domain/ConnectionResponse.php index a8c6818..bf9d7d1 100644 --- a/src/Model/Domain/ConnectionResponse.php +++ b/src/Model/Domain/ConnectionResponse.php @@ -18,14 +18,7 @@ use Mailgun\Model\ApiResponse; */ final class ConnectionResponse implements ApiResponse { - /** - * @var bool - */ private $noVerify; - - /** - * @var bool - */ private $requireTLS; public static function create(array $data): ?self @@ -35,34 +28,31 @@ final class ConnectionResponse implements ApiResponse } $connSettings = $data['connection']; - return new self( - isset($connSettings['skip_verification']) ? $connSettings['skip_verification'] : null, - isset($connSettings['require_tls']) ? $connSettings['require_tls'] : null - ); + $model = new self(); + $model->noVerify = $connSettings['skip_verification'] ?? null; + $model->requireTLS = $connSettings['require_tls'] ?? null; + + return $model; } - /** - * @param bool $noVerify Disable remote TLS certificate verification - * @param bool $requireTLS Requires TLS for all outbound communication - */ - private function __construct($noVerify, $requireTLS) + private function __construct() { - $this->noVerify = $noVerify; - $this->requireTLS = $requireTLS; } /** + * Disable remote TLS certificate verification. * @return bool */ - public function getSkipVerification() + public function getSkipVerification(): ?bool { return $this->noVerify; } /** + * Requires TLS for all outbound communication. * @return bool */ - public function getRequireTLS() + public function getRequireTLS(): ?bool { return $this->requireTLS; } diff --git a/src/Model/Domain/CreateCredentialResponse.php b/src/Model/Domain/CreateCredentialResponse.php index 08a2d2d..bcf3378 100644 --- a/src/Model/Domain/CreateCredentialResponse.php +++ b/src/Model/Domain/CreateCredentialResponse.php @@ -18,31 +18,21 @@ use Mailgun\Model\ApiResponse; */ final class CreateCredentialResponse implements ApiResponse { - /** - * @var string - */ private $message; - /** - * @param string $message - */ - private function __construct($message) + private function __construct() { - $this->message = $message; } - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - return new self(isset($data['message']) ? $data['message'] : null); + $model = new self(); + $model->message = $data['message'] ?? null; + + return $model; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } diff --git a/src/Model/Domain/CredentialResponse.php b/src/Model/Domain/CredentialResponse.php index ddb9253..e5ddca1 100644 --- a/src/Model/Domain/CredentialResponse.php +++ b/src/Model/Domain/CredentialResponse.php @@ -18,20 +18,10 @@ use Mailgun\Model\ApiResponse; */ final class CredentialResponse implements ApiResponse { - /** - * @var int - */ private $totalCount; - - /** - * @var CredentialResponseItem[] - */ private $items; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { $items = []; if (isset($data['items'])) { @@ -41,28 +31,23 @@ final class CredentialResponse implements ApiResponse } if (isset($data['total_count'])) { - $count = $data['total_count']; + $count = (int) $data['total_count']; } else { $count = count($items); } - return new self($count, $items); + $model = new self(); + $model->totalCount = $count; + $model->items = $items; + + return $model; } - /** - * @param int $totalCount - * @param CredentialResponseItem[] $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; } @@ -70,7 +55,7 @@ final class CredentialResponse implements ApiResponse /** * @return CredentialResponseItem[] */ - public function getCredentials() + public function getCredentials(): array { return $this->items; } diff --git a/src/Model/Domain/CredentialResponseItem.php b/src/Model/Domain/CredentialResponseItem.php index de232d0..8f857d4 100644 --- a/src/Model/Domain/CredentialResponseItem.php +++ b/src/Model/Domain/CredentialResponseItem.php @@ -16,80 +16,42 @@ namespace Mailgun\Model\Domain; */ final class CredentialResponseItem { - /** - * @var int|null - */ private $sizeBytes; - - /** - * @var \DateTime - */ private $createdAt; - - /** - * @var string - */ private $mailbox; - - /** - * @var string - */ private $login; - /** - * @return self - */ - public static function create(array $data) + public static function create(array $data): self { - $sizeBytes = isset($data['size_bytes']) ? $data['size_bytes'] : null; - $mailbox = isset($data['mailbox']) ? $data['mailbox'] : null; - $login = isset($data['login']) ? $data['login'] : null; - $createdAt = isset($data['created_at']) ? new \DateTime($data['created_at']) : null; + $model = new self(); + $model->sizeBytes = $data['size_bytes'] ?? null; + $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null; + $model->mailbox = $data['mailbox'] ?? null; + $model->login = $data['login'] ?? null; - return new self($sizeBytes, $createdAt, $mailbox, $login); + return $model; } - /** - * @param int $sizeBytes - * @param string $mailbox - * @param string $login - */ - private function __construct($sizeBytes, \DateTime $createdAt, $mailbox, $login) + private function __construct() { - $this->sizeBytes = $sizeBytes; - $this->createdAt = $createdAt; - $this->mailbox = $mailbox; - $this->login = $login; } - /** - * @return int|null - */ - public function getSizeBytes() + public function getSizeBytes(): ?int { return $this->sizeBytes; } - /** - * @return \DateTime - */ - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; } - /** - * @return string - */ - public function getMailbox() + public function getMailbox(): ?string { return $this->mailbox; } - /** - * @return string - */ - public function getLogin() + public function getLogin(): ?string { return $this->login; } diff --git a/src/Model/Domain/DeleteCredentialResponse.php b/src/Model/Domain/DeleteCredentialResponse.php index a1305ca..26dadf3 100644 --- a/src/Model/Domain/DeleteCredentialResponse.php +++ b/src/Model/Domain/DeleteCredentialResponse.php @@ -18,65 +18,35 @@ use Mailgun\Model\ApiResponse; */ final class DeleteCredentialResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var string - */ private $error; - - /** - * @var string - */ private $spec; - /** - * @param string $message - * @param string $error - * @param string $spec - */ - private function __construct($message, $error, $spec) + private function __construct() { - $this->message = $message; - $this->error = $error; - $this->spec = $spec; } - /** - * @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, - isset($data['spec']) ? $data['spec'] : null - ); + $model = new self(); + $model->message = $data['message'] ?? null; + $model->error = $data['error'] ?? null; + $model->spec = $data['spec'] ?? null; + + return $model; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } - /** - * @return string - */ - public function getError() + public function getError(): ?string { return $this->error; } - /** - * @return string - */ - public function getSpec() + public function getSpec(): ?string { return $this->spec; } diff --git a/src/Model/Domain/DeleteResponse.php b/src/Model/Domain/DeleteResponse.php index a3cbf71..bb3d5c3 100644 --- a/src/Model/Domain/DeleteResponse.php +++ b/src/Model/Domain/DeleteResponse.php @@ -18,49 +18,28 @@ use Mailgun\Model\ApiResponse; */ final class DeleteResponse implements ApiResponse { - /** - * @var string - */ private $message; - - /** - * @var string - */ private $error; - /** - * @param string $message - * @param string $error - */ - private function __construct($message, $error) + private function __construct() { - $this->message = $message; - $this->error = $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; } - /** - * @return string - */ - public function getMessage() + public function getMessage(): ?string { return $this->message; } - /** - * @return string - */ - public function getError() + public function getError(): ?string { return $this->error; }