From b9f7af3c5ee048fc3ff64fae5b9f495dc1e1086b Mon Sep 17 00:00:00 2001 From: dpslwk Date: Fri, 6 Mar 2020 23:10:38 +0000 Subject: [PATCH] Using array_key_exists() on objects is deprecated, so check its an array first --- CHANGELOG.md | 7 +++++ src/ViMbAdminClient.php | 60 ++++++++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a838661..e05dfe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,13 @@ All Notable changes to `ViMbAdminClient` will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## 1.1.2 (released 2020-03-06) + +### Fixed +- Handle relationships with out data +- Using array_key_exists() on objects is deprecated (php 7.4) + + ## 1.1.1 (released 2020-01-02) ### Fixed diff --git a/src/ViMbAdminClient.php b/src/ViMbAdminClient.php index 8f40183..a97e9dc 100644 --- a/src/ViMbAdminClient.php +++ b/src/ViMbAdminClient.php @@ -206,7 +206,11 @@ public function createAlias(Alias $alias) $uri = $alias->getDomain()->getDomain().'/aliases/'.$alias->getId(); $response = $this->post($uri, json_encode($alias)); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -219,7 +223,11 @@ public function createMailbox(Mailbox $mailbox) $uri = $mailbox->getDomain()->getDomain().'/mailboxes/'.$mailbox->getId(); $response = $this->post($uri, json_encode($mailbox)); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -238,7 +246,11 @@ public function findAliasesForDomain(string $domainName, $query = null) $response = $this->get($uri); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -267,7 +279,11 @@ public function findDomains($query = null, $includes = null) $response = $this->get($uri); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -286,7 +302,11 @@ public function findMailboxesForDomain(string $domainName, $query = null) $response = $this->get($uri); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -300,7 +320,11 @@ public function getAliasForDomain(string $domainName, int $aliasId) $uri = $domainName.'/aliases/'.$aliasId; $response = $this->get($uri); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -323,7 +347,11 @@ public function getDomain(int $domainId, $includes = null) $response = $this->get($uri); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -337,7 +365,11 @@ public function getMailboxForDomain(string $domainName, int $mailboxId) $uri = $domainName.'/mailboxes/'.$mailboxId; $response = $this->get($uri); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -350,7 +382,11 @@ public function updateAlias(Alias $alias) $uri = $alias->getDomain()->getDomain().'/aliases/'.$alias->getId(); $response = $this->patch($uri, json_encode($alias)); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } /** @@ -363,6 +399,10 @@ public function updateMailbox(Mailbox $mailbox) $uri = $mailbox->getDomain()->getDomain().'/mailboxes/'.$mailbox->getId(); $response = $this->patch($uri, json_encode($mailbox)); - return array_key_exists('errors', $response) ? $response['errors'][0] : $response; + if (is_array($response) && array_key_exists('errors', $response)) { + return $response['errors'][0]; + } + + return $response; } }