Updated other domain models

This commit is contained in:
Nyholm 2019-01-13 21:44:33 +01:00 committed by David Garcia
parent 0c3b716cf2
commit 47ef0542f0
6 changed files with 83 additions and 262 deletions

View File

@ -18,121 +18,81 @@ namespace Mailgun\Model\Domain;
*/ */
final class DnsRecord final class DnsRecord
{ {
/**
* @var string|null
*/
private $name; private $name;
/**
* @var string
*/
private $type; private $type;
/**
* @var string
*/
private $value; private $value;
/**
* @var string|null
*/
private $priority; private $priority;
/**
* @var string
*/
private $valid; private $valid;
/**
* @var array
*/
private $cached; private $cached;
/** public static function create(array $data): self
* @return self
*/
public static function create(array $data)
{ {
$name = isset($data['name']) ? $data['name'] : null; $model = new self();
$priority = isset($data['priority']) ? $data['priority'] : null; $model->name = $data['name'] ?? null;
$recordType = isset($data['record_type']) ? $data['record_type'] : null; $model->type = $data['record_type'] ?? null;
$value = isset($data['value']) ? $data['value'] : null; $model->value = $data['value'] ?? null;
$valid = isset($data['valid']) ? $data['valid'] : null; $model->priority = $data['priority'] ?? null;
$cached = isset($data['cached']) ? $data['cached'] : null; $model->valid = $data['valid'] ?? null;
$model->cached = $data['cached'] ?? [];
return new self($name, $recordType, $value, $priority, $valid, $cached); return $model;
}
private function __construct()
{
} }
/** /**
* @param string|null $name name of the record, as used in CNAME, etc * name of the record, as used in CNAME, etc.
* @param string $type DNS record type
* @param string $value DNS record value
* @param string|null $priority Record priority, used for MX
* @param string $valid DNS record has been added to domain DNS?
* @param array $cached DNS record current value
*/ */
private function __construct($name, $type, $value, $priority, $valid, $cached) public function getName(): ?string
{
$this->name = $name;
$this->type = $type;
$this->value = $value;
$this->priority = $priority;
$this->valid = $valid;
$this->cached = $cached;
}
/**
* @return string|null
*/
public function getName()
{ {
return $this->name; return $this->name;
} }
/** /**
* DNS record type.
*
* @return string * @return string
*/ */
public function getType() public function getType(): ?string
{ {
return $this->type; return $this->type;
} }
/** /**
* @return string * DNS record value.
*/ */
public function getValue() public function getValue(): ?string
{ {
return $this->value; return $this->value;
} }
/** /**
* @return string|null * Record priority, used for MX.
*/ */
public function getPriority() public function getPriority(): ?string
{ {
return $this->priority; return $this->priority;
} }
/** /**
* @return bool * DNS record has been added to domain DNS?
*/ */
public function isValid() public function isValid(): bool
{ {
return 'valid' === $this->valid; return 'valid' === $this->valid;
} }
/** public function getValidity(): ?string
* @return string
*/
public function getValidity()
{ {
return $this->valid; return $this->valid;
} }
/** /**
* @return array * DNS record current value.
*/ */
public function getCached() public function getCached(): array
{ {
return $this->cached; return $this->cached;
} }

View File

@ -18,128 +18,63 @@ namespace Mailgun\Model\Domain;
*/ */
final class Domain final class Domain
{ {
/**
* @var \DateTime
*/
private $createdAt; private $createdAt;
/**
* @var string
*/
private $smtpLogin; private $smtpLogin;
/**
* @var string
*/
private $name; private $name;
/**
* @var string
*/
private $smtpPassword; private $smtpPassword;
/**
* @var bool
*/
private $wildcard; private $wildcard;
/**
* @var string
*/
private $spamAction; private $spamAction;
/**
* @var string
*/
private $state; private $state;
/** public static function create(array $data): self
* @return self
*/
public static function create(array $data)
{ {
return new self( $model = new self();
isset($data['name']) ? $data['name'] : null, $model->name = $data['name'] ?? null;
isset($data['smtp_login']) ? $data['smtp_login'] : null, $model->smtpLogin = $data['smtp_login'] ?? null;
isset($data['smtp_password']) ? $data['smtp_password'] : null, $model->smtpPassword = $data['smtp_password'] ?? null;
isset($data['wildcard']) ? $data['wildcard'] : null, $model->wildcard = $data['wildcard'] ?? null;
isset($data['spam_action']) ? $data['spam_action'] : null, $model->spamAction = $data['spam_action'] ?? null;
isset($data['state']) ? $data['state'] : null, $model->state = $data['state'] ?? null;
isset($data['created_at']) ? new \DateTime($data['created_at']) : null $model->createdAt = isset($data['created_at']) ? new \DateTimeImmutable($data['created_at']) : null;
);
return $model;
} }
/** private function __construct()
* @param string $name
* @param string $smtpLogin
* @param string $smtpPassword
* @param bool $wildcard
* @param string $spamAction
* @param string $state
*/
private function __construct($name, $smtpLogin, $smtpPassword, $wildcard, $spamAction, $state, \DateTime $createdAt)
{ {
$this->name = $name;
$this->smtpLogin = $smtpLogin;
$this->smtpPassword = $smtpPassword;
$this->wildcard = $wildcard;
$this->spamAction = $spamAction;
$this->state = $state;
$this->createdAt = $createdAt;
} }
/** public function getName(): ?string
* @return string
*/
public function getName()
{ {
return $this->name; return $this->name;
} }
/** public function getSmtpUsername(): ?string
* @return string
*/
public function getSmtpUsername()
{ {
return $this->smtpLogin; return $this->smtpLogin;
} }
/** public function getSmtpPassword(): ?string
* @return string
*/
public function getSmtpPassword()
{ {
return $this->smtpPassword; return $this->smtpPassword;
} }
/** public function isWildcard(): ?bool
* @return bool
*/
public function isWildcard()
{ {
return $this->wildcard; return $this->wildcard;
} }
/** public function getSpamAction(): ?string
* @return string
*/
public function getSpamAction()
{ {
return $this->spamAction; return $this->spamAction;
} }
/** public function getState(): ?string
* @return string
*/
public function getState()
{ {
return $this->state; return $this->state;
} }
/** public function getCreatedAt(): \DateTimeImmutable
* @return \DateTime
*/
public function getCreatedAt()
{ {
return $this->createdAt; return $this->createdAt;
} }

View File

@ -18,20 +18,10 @@ use Mailgun\Model\ApiResponse;
*/ */
final class IndexResponse implements ApiResponse final class IndexResponse implements ApiResponse
{ {
/**
* @var int
*/
private $totalCount; private $totalCount;
/**
* @var Domain[]
*/
private $items; private $items;
/** public static function create(array $data): self
* @return self
*/
public static function create(array $data)
{ {
$items = []; $items = [];
@ -47,23 +37,18 @@ final class IndexResponse implements ApiResponse
$count = count($items); $count = count($items);
} }
return new self($count, $items); $model = new self();
$model->totalCount = $count;
$model->items = $items;
return $model;
} }
/** private function __construct()
* @param int $totalCount
* @param Domain[] $items
*/
private function __construct($totalCount, array $items)
{ {
$this->totalCount = $totalCount;
$this->items = $items;
} }
/** public function getTotalCount(): int
* @return int
*/
public function getTotalCount()
{ {
return $this->totalCount; return $this->totalCount;
} }
@ -71,7 +56,7 @@ final class IndexResponse implements ApiResponse
/** /**
* @return Domain[] * @return Domain[]
*/ */
public function getDomains() public function getDomains(): array
{ {
return $this->items; return $this->items;
} }

View File

@ -18,25 +18,11 @@ use Mailgun\Model\ApiResponse;
*/ */
final class ShowResponse implements ApiResponse final class ShowResponse implements ApiResponse
{ {
/**
* @var Domain
*/
private $domain; private $domain;
/**
* @var DnsRecord[]
*/
private $inboundDnsRecords; private $inboundDnsRecords;
/**
* @var DnsRecord[]
*/
private $outboundDnsRecords; private $outboundDnsRecords;
/** public static function create(array $data): self
* @return self
*/
public static function create(array $data)
{ {
$rx = []; $rx = [];
$tx = []; $tx = [];
@ -58,24 +44,19 @@ final class ShowResponse implements ApiResponse
} }
} }
return new self($domain, $rx, $tx); $model = new self();
$model->domain = $domain;
$model->inboundDnsRecords = $rx;
$model->outboundDnsRecords = $tx;
return $model;
} }
/** private function __construct()
* @param DnsRecord[] $rxRecords
* @param DnsRecord[] $txRecords
*/
private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords)
{ {
$this->domain = $domainInfo;
$this->inboundDnsRecords = $rxRecords;
$this->outboundDnsRecords = $txRecords;
} }
/** public function getDomain(): ?Domain
* @return Domain
*/
public function getDomain()
{ {
return $this->domain; return $this->domain;
} }
@ -83,7 +64,7 @@ final class ShowResponse implements ApiResponse
/** /**
* @return DnsRecord[] * @return DnsRecord[]
*/ */
public function getInboundDNSRecords() public function getInboundDNSRecords(): array
{ {
return $this->inboundDnsRecords; return $this->inboundDnsRecords;
} }
@ -91,7 +72,7 @@ final class ShowResponse implements ApiResponse
/** /**
* @return DnsRecord[] * @return DnsRecord[]
*/ */
public function getOutboundDNSRecords() public function getOutboundDNSRecords(): array
{ {
return $this->outboundDnsRecords; return $this->outboundDnsRecords;
} }

View File

@ -18,65 +18,35 @@ use Mailgun\Model\ApiResponse;
*/ */
final class UpdateConnectionResponse implements ApiResponse final class UpdateConnectionResponse implements ApiResponse
{ {
/**
* @var string
*/
private $message; private $message;
/**
* @var bool
*/
private $noVerify; private $noVerify;
/**
* @var bool
*/
private $requireTLS; private $requireTLS;
/** public static function create(array $data): self
* @return self
*/
public static function create(array $data)
{ {
$message = isset($data['message']) ? $data['message'] : null; $model = new self();
$noVerify = isset($data['skip-verification']) ? $data['skip-verification'] : null; $model->message = $data['message'] ?? null;
$requireTLS = isset($data['require-tls']) ? $data['require-tls'] : null; $model->noVerify = $data['skip-verification'] ?? null;
$model->requireTLS = $data['require-tls'] ?? null;
return new self($message, $noVerify, $requireTLS); return $model;
} }
/** private function __construct()
* @param string $message
* @param bool $noVerify
* @param bool $requireTLS
*/
private function __construct($message, $noVerify, $requireTLS)
{ {
$this->message = $message;
$this->noVerify = $noVerify;
$this->requireTLS = $requireTLS;
} }
/** public function getMessage(): ?string
* @return string
*/
public function getMessage()
{ {
return $this->message; return $this->message;
} }
/** public function getSkipVerification(): ?bool
* @return bool
*/
public function getSkipVerification()
{ {
return $this->noVerify; return $this->noVerify;
} }
/** public function getRequireTLS(): ?bool
* @return bool
*/
public function getRequireTLS()
{ {
return $this->requireTLS; return $this->requireTLS;
} }

View File

@ -18,31 +18,21 @@ use Mailgun\Model\ApiResponse;
*/ */
final class UpdateCredentialResponse implements ApiResponse final class UpdateCredentialResponse implements ApiResponse
{ {
/**
* @var string
*/
private $message; private $message;
/** public static function create(array $data): self
* @param string $message
*/
private function __construct($message)
{ {
$this->message = $message; $model = new self();
$model->message = $data['message'] ?? null;
return $model;
} }
/** private function __construct()
* @return self
*/
public static function create(array $data)
{ {
return new self(isset($data['message']) ? $data['message'] : null);
} }
/** public function getMessage(): ?string
* @return string
*/
public function getMessage()
{ {
return $this->message; return $this->message;
} }