mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2025-02-06 08:19:25 +03:00
Updated some models with PHP 7 code
This commit is contained in:
parent
3fbd33f640
commit
0c3b716cf2
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user