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
{
/**
* @var string|null
*/
private $name;
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $value;
/**
* @var string|null
*/
private $priority;
/**
* @var string
*/
private $valid;
/**
* @var array
*/
private $cached;
/**
* @return self
*/
public static function create(array $data)
public static function create(array $data): self
{
$name = isset($data['name']) ? $data['name'] : null;
$priority = isset($data['priority']) ? $data['priority'] : null;
$recordType = isset($data['record_type']) ? $data['record_type'] : null;
$value = isset($data['value']) ? $data['value'] : null;
$valid = isset($data['valid']) ? $data['valid'] : null;
$cached = isset($data['cached']) ? $data['cached'] : null;
$model = new self();
$model->name = $data['name'] ?? null;
$model->type = $data['record_type'] ?? null;
$model->value = $data['value'] ?? null;
$model->priority = $data['priority'] ?? 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
* @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
* name of the record, as used in CNAME, etc.
*/
private function __construct($name, $type, $value, $priority, $valid, $cached)
{
$this->name = $name;
$this->type = $type;
$this->value = $value;
$this->priority = $priority;
$this->valid = $valid;
$this->cached = $cached;
}
/**
* @return string|null
*/
public function getName()
public function getName(): ?string
{
return $this->name;
}
/**
* DNS record type.
*
* @return string
*/
public function getType()
public function getType(): ?string
{
return $this->type;
}
/**
* @return string
* DNS record value.
*/
public function getValue()
public function getValue(): ?string
{
return $this->value;
}
/**
* @return string|null
* Record priority, used for MX.
*/
public function getPriority()
public function getPriority(): ?string
{
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 string
*/
public function getValidity()
public function getValidity(): ?string
{
return $this->valid;
}
/**
* @return array
* DNS record current value.
*/
public function getCached()
public function getCached(): array
{
return $this->cached;
}

View File

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

View File

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

View File

@ -18,25 +18,11 @@ use Mailgun\Model\ApiResponse;
*/
final class ShowResponse implements ApiResponse
{
/**
* @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 = [];
@ -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;
}
/**
* @param DnsRecord[] $rxRecords
* @param DnsRecord[] $txRecords
*/
private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords)
private function __construct()
{
$this->domain = $domainInfo;
$this->inboundDnsRecords = $rxRecords;
$this->outboundDnsRecords = $txRecords;
}
/**
* @return Domain
*/
public function getDomain()
public function getDomain(): ?Domain
{
return $this->domain;
}
@ -83,7 +64,7 @@ final class ShowResponse implements ApiResponse
/**
* @return DnsRecord[]
*/
public function getInboundDNSRecords()
public function getInboundDNSRecords(): array
{
return $this->inboundDnsRecords;
}
@ -91,7 +72,7 @@ final class ShowResponse implements ApiResponse
/**
* @return DnsRecord[]
*/
public function getOutboundDNSRecords()
public function getOutboundDNSRecords(): array
{
return $this->outboundDnsRecords;
}

View File

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

View File

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