From d12ea9f456203217c06d61af3e7e7f5c25763722 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Tue, 6 Dec 2016 07:44:59 +0100 Subject: [PATCH] =?UTF-8?q?Do=20not=20validate=20API=20responses.=20Create?= =?UTF-8?q?=20Response=20objects=20that=20have=20part=E2=80=A6=20(#230)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Do not validate API responses. Create Response objects that have partial data instead Fix issue #225 * Code style --- .../Api/Domain/ConnectionResponse.php | 16 ++++---- .../Api/Domain/CreateCredentialResponse.php | 5 ++- .../Resource/Api/Domain/CreateResponse.php | 37 ++++++++++++------- .../Api/Domain/CredentialResponse.php | 26 ++++++------- .../Api/Domain/CredentialResponseItem.php | 29 ++++----------- .../Api/Domain/DeleteCredentialResponse.php | 7 +++- src/Mailgun/Resource/Api/Domain/DnsRecord.php | 16 +++----- src/Mailgun/Resource/Api/Domain/Domain.php | 27 +++++--------- .../Resource/Api/Domain/IndexResponse.php | 22 +++++------ .../Resource/Api/Domain/ShowResponse.php | 27 ++++++++------ .../Api/Domain/UpdateConnectionResponse.php | 24 +++--------- .../Api/Domain/UpdateCredentialResponse.php | 5 ++- src/Mailgun/Resource/Api/ErrorResponse.php | 5 ++- .../Resource/Api/Stats/AllResponse.php | 17 +++++++-- .../Resource/Api/Stats/AllResponseItem.php | 19 +++++----- .../Resource/Api/Stats/TotalResponse.php | 15 ++++++-- .../Resource/Api/Stats/TotalResponseItem.php | 17 ++++----- 17 files changed, 152 insertions(+), 162 deletions(-) diff --git a/src/Mailgun/Resource/Api/Domain/ConnectionResponse.php b/src/Mailgun/Resource/Api/Domain/ConnectionResponse.php index 045ae9e..4ed4eb9 100644 --- a/src/Mailgun/Resource/Api/Domain/ConnectionResponse.php +++ b/src/Mailgun/Resource/Api/Domain/ConnectionResponse.php @@ -4,12 +4,12 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; use Mailgun\Resource\ApiResponse; /** @@ -34,16 +34,14 @@ final class ConnectionResponse implements ApiResponse */ public static function create(array $data) { - Assert::keyExists($data, 'connection'); - Assert::isArray($data['connection']); + if (!isset($data['connection'])) { + return; + } $connSettings = $data['connection']; - Assert::keyExists($connSettings, 'skip_verification'); - Assert::keyExists($connSettings, 'require_tls'); - return new self( - $connSettings['skip_verification'], - $connSettings['require_tls'] + isset($connSettings['skip_verification']) ? $connSettings['skip_verification'] : null, + isset($connSettings['require_tls']) ? $connSettings['require_tls'] : null ); } diff --git a/src/Mailgun/Resource/Api/Domain/CreateCredentialResponse.php b/src/Mailgun/Resource/Api/Domain/CreateCredentialResponse.php index 9b5f590..ce05897 100644 --- a/src/Mailgun/Resource/Api/Domain/CreateCredentialResponse.php +++ b/src/Mailgun/Resource/Api/Domain/CreateCredentialResponse.php @@ -4,9 +4,10 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; use Mailgun\Resource\ApiResponse; @@ -36,7 +37,7 @@ final class CreateCredentialResponse implements ApiResponse */ public static function create(array $data) { - return new self($data['message']); + return new self(isset($data['message']) ? $data['message'] : null); } /** diff --git a/src/Mailgun/Resource/Api/Domain/CreateResponse.php b/src/Mailgun/Resource/Api/Domain/CreateResponse.php index 650c644..1183a3d 100644 --- a/src/Mailgun/Resource/Api/Domain/CreateResponse.php +++ b/src/Mailgun/Resource/Api/Domain/CreateResponse.php @@ -4,12 +4,12 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; use Mailgun\Resource\ApiResponse; /** @@ -44,23 +44,32 @@ final class CreateResponse implements ApiResponse */ public static function create(array $data) { - Assert::keyExists($data, 'domain'); - Assert::keyExists($data, 'message'); - Assert::keyExists($data, 'receiving_dns_records'); - Assert::keyExists($data, 'sending_dns_records'); - - $domain = Domain::create($data['domain']); $rx = []; $tx = []; + $domain = null; + $message = null; - foreach ($data['receiving_dns_records'] as $item) { - $rx[] = DnsRecord::create($item); - } - foreach ($data['sending_dns_records'] as $item) { - $tx[] = DnsRecord::create($item); + if (isset($data['domain'])) { + $domain = Domain::create($data['domain']); } - return new self($domain, $rx, $tx, $data['message']); + if (isset($data['message'])) { + $message = $data['message']; + } + + if (isset($data['receiving_dns_records'])) { + foreach ($data['receiving_dns_records'] as $item) { + $rx[] = DnsRecord::create($item); + } + } + + if (isset($data['sending_dns_records'])) { + foreach ($data['sending_dns_records'] as $item) { + $tx[] = DnsRecord::create($item); + } + } + + return new self($domain, $rx, $tx, $message); } /** diff --git a/src/Mailgun/Resource/Api/Domain/CredentialResponse.php b/src/Mailgun/Resource/Api/Domain/CredentialResponse.php index 9212439..1a32ebc 100644 --- a/src/Mailgun/Resource/Api/Domain/CredentialResponse.php +++ b/src/Mailgun/Resource/Api/Domain/CredentialResponse.php @@ -4,14 +4,13 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; use Mailgun\Resource\ApiResponse; -use Mailgun\Resource\Api\ErrorResponse; /** * @author Sean Johnson @@ -35,17 +34,20 @@ final class CredentialResponse implements ApiResponse */ public static function create(array $data) { - if (array_key_exists('items', $data) && array_key_exists('total_count', $data)) { - $items = []; - + $items = []; + if (isset($data['items'])) { foreach ($data['items'] as $item) { $items[] = CredentialResponseItem::create($item); } - - return new self($data['total_count'], $items); - } else { - return ErrorResponse::create($data); } + + if (isset($data['total_count'])) { + $count = $data['total_count']; + } else { + $count = count($items); + } + + return new self($count, $items); } /** @@ -54,10 +56,6 @@ final class CredentialResponse implements ApiResponse */ private function __construct($totalCount, array $items) { - Assert::integer($totalCount); - Assert::isArray($items); - Assert::allIsInstanceOf($items, 'Mailgun\Resource\Api\Domain\CredentialResponseItem'); - $this->totalCount = $totalCount; $this->items = $items; } diff --git a/src/Mailgun/Resource/Api/Domain/CredentialResponseItem.php b/src/Mailgun/Resource/Api/Domain/CredentialResponseItem.php index bd358c2..38275e2 100644 --- a/src/Mailgun/Resource/Api/Domain/CredentialResponseItem.php +++ b/src/Mailgun/Resource/Api/Domain/CredentialResponseItem.php @@ -4,12 +4,11 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; +namespace Mailgun\Resource\Api\Domain; /** * @author Sean Johnson @@ -43,26 +42,12 @@ final class CredentialResponseItem */ public static function create(array $data) { - Assert::keyExists($data, 'created_at'); - Assert::keyExists($data, 'mailbox'); - Assert::keyExists($data, 'login'); + $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; - $sizeBytes = array_key_exists('size_bytes', $data) ? $data['size_bytes'] : null; - $createdAt = new \DateTime($data['created_at']); - $mailbox = $data['mailbox']; - $login = $data['login']; - - Assert::nullOrInteger($sizeBytes); - Assert::isInstanceOf($createdAt, '\DateTime'); - Assert::string($mailbox); - Assert::string($login); - - return new self( - $sizeBytes, - $createdAt, - $mailbox, - $login - ); + return new self($sizeBytes, $createdAt, $mailbox, $login); } /** diff --git a/src/Mailgun/Resource/Api/Domain/DeleteCredentialResponse.php b/src/Mailgun/Resource/Api/Domain/DeleteCredentialResponse.php index 730dabf..cb587eb 100644 --- a/src/Mailgun/Resource/Api/Domain/DeleteCredentialResponse.php +++ b/src/Mailgun/Resource/Api/Domain/DeleteCredentialResponse.php @@ -4,9 +4,10 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; use Mailgun\Resource\ApiResponse; @@ -22,7 +23,7 @@ final class DeleteCredentialResponse implements ApiResponse private $message; /** - * @var error + * @var string */ private $error; @@ -33,6 +34,8 @@ final class DeleteCredentialResponse implements ApiResponse /** * @param string $message + * @param string $error + * @param string $spec */ private function __construct($message, $error, $spec) { diff --git a/src/Mailgun/Resource/Api/Domain/DnsRecord.php b/src/Mailgun/Resource/Api/Domain/DnsRecord.php index f513ab9..6478001 100644 --- a/src/Mailgun/Resource/Api/Domain/DnsRecord.php +++ b/src/Mailgun/Resource/Api/Domain/DnsRecord.php @@ -4,12 +4,11 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; +namespace Mailgun\Resource\Api\Domain; /** * Represents a single DNS record for a domain. @@ -52,14 +51,11 @@ final class DnsRecord { $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; - Assert::nullOrString($name); - Assert::string($data['record_type']); - Assert::string($data['value']); - Assert::nullOrString($priority); - Assert::string($data['valid']); - - return new self($name, $data['record_type'], $data['value'], $priority, $data['valid']); + return new self($name, $recordType, $value, $priority, $valid); } /** diff --git a/src/Mailgun/Resource/Api/Domain/Domain.php b/src/Mailgun/Resource/Api/Domain/Domain.php index 53b6079..d3a0403 100644 --- a/src/Mailgun/Resource/Api/Domain/Domain.php +++ b/src/Mailgun/Resource/Api/Domain/Domain.php @@ -4,12 +4,11 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; +namespace Mailgun\Resource\Api\Domain; /** * Represents domain information in its simplest form. @@ -60,22 +59,14 @@ final class Domain */ public static function create(array $data) { - Assert::keyExists($data, 'name'); - Assert::keyExists($data, 'smtp_login'); - Assert::keyExists($data, 'smtp_password'); - Assert::keyExists($data, 'wildcard'); - Assert::keyExists($data, 'spam_action'); - Assert::keyExists($data, 'state'); - Assert::keyExists($data, 'created_at'); - return new self( - $data['name'], - $data['smtp_login'], - $data['smtp_password'], - $data['wildcard'], - $data['spam_action'], - $data['state'], - new \DateTime($data['created_at']) + 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 ); } diff --git a/src/Mailgun/Resource/Api/Domain/IndexResponse.php b/src/Mailgun/Resource/Api/Domain/IndexResponse.php index 0c36794..c5d5e20 100644 --- a/src/Mailgun/Resource/Api/Domain/IndexResponse.php +++ b/src/Mailgun/Resource/Api/Domain/IndexResponse.php @@ -10,7 +10,6 @@ namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; use Mailgun\Resource\ApiResponse; /** @@ -37,14 +36,19 @@ final class IndexResponse implements ApiResponse { $items = []; - Assert::keyExists($data, 'total_count'); - Assert::keyExists($data, 'items'); - - foreach ($data['items'] as $item) { - $items[] = Domain::create($item); + if (isset($data['items'])) { + foreach ($data['items'] as $item) { + $items[] = Domain::create($item); + } } - return new self($data['total_count'], $items); + if (isset($data['total_count'])) { + $count = $data['total_count']; + } else { + $count = count($items); + } + + return new self($count, $items); } /** @@ -53,10 +57,6 @@ final class IndexResponse implements ApiResponse */ private function __construct($totalCount, array $items) { - Assert::integer($totalCount); - Assert::isArray($items); - Assert::allIsInstanceOf($items, 'Mailgun\Resource\Api\Domain\Domain'); - $this->totalCount = $totalCount; $this->items = $items; } diff --git a/src/Mailgun/Resource/Api/Domain/ShowResponse.php b/src/Mailgun/Resource/Api/Domain/ShowResponse.php index da32f3a..323d7de 100644 --- a/src/Mailgun/Resource/Api/Domain/ShowResponse.php +++ b/src/Mailgun/Resource/Api/Domain/ShowResponse.php @@ -4,12 +4,12 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; use Mailgun\Resource\ApiResponse; /** @@ -39,19 +39,24 @@ final class ShowResponse implements ApiResponse */ public static function create(array $data) { - Assert::keyExists($data, 'domain'); - Assert::keyExists($data, 'receiving_dns_records'); - Assert::keyExists($data, 'sending_dns_records'); - - $domain = Domain::create($data['domain']); $rx = []; $tx = []; + $domain = null; - foreach ($data['receiving_dns_records'] as $item) { - $rx[] = DnsRecord::create($item); + if (isset($data['domain'])) { + $domain = Domain::create($data['domain']); } - foreach ($data['sending_dns_records'] as $item) { - $tx[] = DnsRecord::create($item); + + if (isset($data['receiving_dns_records'])) { + foreach ($data['receiving_dns_records'] as $item) { + $rx[] = DnsRecord::create($item); + } + } + + if (isset($data['sending_dns_records'])) { + foreach ($data['sending_dns_records'] as $item) { + $tx[] = DnsRecord::create($item); + } } return new self($domain, $rx, $tx); diff --git a/src/Mailgun/Resource/Api/Domain/UpdateConnectionResponse.php b/src/Mailgun/Resource/Api/Domain/UpdateConnectionResponse.php index 3354ce1..d39002e 100644 --- a/src/Mailgun/Resource/Api/Domain/UpdateConnectionResponse.php +++ b/src/Mailgun/Resource/Api/Domain/UpdateConnectionResponse.php @@ -4,12 +4,12 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; -use Mailgun\Assert; use Mailgun\Resource\ApiResponse; /** @@ -39,23 +39,11 @@ final class UpdateConnectionResponse implements ApiResponse */ public static function create(array $data) { - Assert::keyExists($data, 'message'); - Assert::keyExists($data, 'skip_verification'); - Assert::keyExists($data, 'require_tls'); + $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; - $message = $data['message']; - $noVerify = $data['skip_verification']; - $requireTLS = $data['require_tls']; - - Assert::nullOrString($message); - Assert::boolean($noVerify); - Assert::boolean($requireTLS); - - return new self( - $message, - $noVerify, - $requireTLS - ); + return new self($message, $noVerify, $requireTLS); } /** diff --git a/src/Mailgun/Resource/Api/Domain/UpdateCredentialResponse.php b/src/Mailgun/Resource/Api/Domain/UpdateCredentialResponse.php index 9f7bf05..2c4ead7 100644 --- a/src/Mailgun/Resource/Api/Domain/UpdateCredentialResponse.php +++ b/src/Mailgun/Resource/Api/Domain/UpdateCredentialResponse.php @@ -4,9 +4,10 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Domain; use Mailgun\Resource\ApiResponse; @@ -36,7 +37,7 @@ final class UpdateCredentialResponse implements ApiResponse */ public static function create(array $data) { - return new self($data['message']); + return new self(isset($data['message']) ? $data['message'] : null); } /** diff --git a/src/Mailgun/Resource/Api/ErrorResponse.php b/src/Mailgun/Resource/Api/ErrorResponse.php index f093e84..c759e34 100644 --- a/src/Mailgun/Resource/Api/ErrorResponse.php +++ b/src/Mailgun/Resource/Api/ErrorResponse.php @@ -4,9 +4,10 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api; use Mailgun\Resource\ApiResponse; @@ -33,7 +34,7 @@ final class ErrorResponse implements ApiResponse } /** - * @param array data + * @param array * * @return self */ diff --git a/src/Mailgun/Resource/Api/Stats/AllResponse.php b/src/Mailgun/Resource/Api/Stats/AllResponse.php index 29835d4..1065cdf 100644 --- a/src/Mailgun/Resource/Api/Stats/AllResponse.php +++ b/src/Mailgun/Resource/Api/Stats/AllResponse.php @@ -4,9 +4,10 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Stats; use Mailgun\Resource\ApiResponse; @@ -44,11 +45,19 @@ final class AllResponse implements ApiResponse public static function create(array $data) { $items = []; - foreach ($data['items'] as $i) { - $items[] = AllResponseItem::create($i); + if (isset($data['items'])) { + foreach ($data['items'] as $i) { + $items[] = AllResponseItem::create($i); + } } - return new self($data['total_count'], $items); + if (isset($data['total_count'])) { + $count = $data['total_count']; + } else { + $count = count($items); + } + + return new self($count, $items); } /** diff --git a/src/Mailgun/Resource/Api/Stats/AllResponseItem.php b/src/Mailgun/Resource/Api/Stats/AllResponseItem.php index ab52a05..b3c6a18 100644 --- a/src/Mailgun/Resource/Api/Stats/AllResponseItem.php +++ b/src/Mailgun/Resource/Api/Stats/AllResponseItem.php @@ -4,12 +4,11 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Resource\Api\Stats; -use Mailgun\Assert; +namespace Mailgun\Resource\Api\Stats; /** * @author Tobias Nyholm @@ -48,13 +47,13 @@ final class AllResponseItem */ public static function create(array $data) { - Assert::string($data['id']); - Assert::string($data['event']); - Assert::string($data['total_count']); - Assert::isArray($data['tags']); - Assert::string($data['created_at']); - - return new self($data['id'], $data['event'], $data['total_count'], $data['tags'], new \DateTime($data['created_at'])); + return new self( + isset($data['id']) ? $data['id'] : null, + isset($data['event']) ? $data['event'] : null, + isset($data['total_count']) ? $data['total_count'] : null, + isset($data['tags']) ? $data['tags'] : null, + isset($data['created_at']) ? new \DateTime($data['created_at']) : null + ); } /** diff --git a/src/Mailgun/Resource/Api/Stats/TotalResponse.php b/src/Mailgun/Resource/Api/Stats/TotalResponse.php index 4b818a9..6163c1d 100644 --- a/src/Mailgun/Resource/Api/Stats/TotalResponse.php +++ b/src/Mailgun/Resource/Api/Stats/TotalResponse.php @@ -4,9 +4,10 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ + namespace Mailgun\Resource\Api\Stats; use Mailgun\Resource\ApiResponse; @@ -58,11 +59,17 @@ final class TotalResponse implements ApiResponse public static function create(array $data) { $stats = []; - foreach ($data['stats'] as $s) { - $stats[] = TotalResponseItem::create($s); + if (isset($data['status'])) { + foreach ($data['stats'] as $s) { + $stats[] = TotalResponseItem::create($s); + } } - return new self(new \DateTime($data['start']), new \DateTime($data['end']), $data['resolution'], $stats); + $start = isset($data['start']) ? new \DateTime($data['start']) : null; + $end = isset($data['end']) ? new \DateTime($data['end']) : null; + $resolution = isset($data['resolution']) ? $data['resolution'] : null; + + return new self($start, $end, $resolution, $stats); } /** diff --git a/src/Mailgun/Resource/Api/Stats/TotalResponseItem.php b/src/Mailgun/Resource/Api/Stats/TotalResponseItem.php index 4f0af57..f0166e7 100644 --- a/src/Mailgun/Resource/Api/Stats/TotalResponseItem.php +++ b/src/Mailgun/Resource/Api/Stats/TotalResponseItem.php @@ -4,12 +4,11 @@ * Copyright (C) 2013-2016 Mailgun * * This software may be modified and distributed under the terms - * of the MIT license. See the LICENSE file for details. + * of the MIT license. See the LICENSE file for details. */ -namespace Mailgun\Resource\Api\Stats; -use Mailgun\Assert; +namespace Mailgun\Resource\Api\Stats; /** * @author Tobias Nyholm @@ -43,12 +42,12 @@ class TotalResponseItem */ public static function create(array $data) { - Assert::string($data['time']); - Assert::isArray($data['accepted']); - Assert::isArray($data['delivered']); - Assert::isArray($data['failed']); - - return new self(new \DateTime($data['time']), $data['accepted'], $data['delivered'], $data['failed']); + return new self( + isset($data['time']) ? new \DateTime($data['time']) : null, + isset($data['accepted']) ? $data['accepted'] : null, + isset($data['delivered']) ? $data['delivered'] : null, + isset($data['failed']) ? $data['failed'] : null + ); } /**