Skip to content

Commit

Permalink
Using array_key_exists() on objects is deprecated, so check its an ar…
Browse files Browse the repository at this point in the history
…ray first
  • Loading branch information
dpslwk committed Mar 6, 2020
1 parent fe2f6da commit b9f7af3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 50 additions & 10 deletions src/ViMbAdminClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
}

0 comments on commit b9f7af3

Please sign in to comment.