Skip to content

Commit

Permalink
Merge pull request #5 from mailmotor/fixes
Browse files Browse the repository at this point in the history
Fixes wrong return types in methods like Subscribe/Unsubscribe
  • Loading branch information
jeroendesloovere authored Sep 28, 2017
2 parents b07df3d + eb29ea3 commit 4b5c4ac
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Gateway/MailChimpSubscriberGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(Mailchimp $api)
public function exists(string $email, string $listId): bool
{
try {
// Define result
/** @var array $result */
$result = $this->get(
$email,
$listId
Expand All @@ -45,9 +45,9 @@ public function exists(string $email, string $listId): bool
*
* @param string $email
* @param string $listId
* @return mixed boolean|Collection
* @return array
*/
private function get(string $email, string $listId)
private function get(string $email, string $listId): array
{
try {
/** @var Collection $result */
Expand All @@ -60,7 +60,7 @@ private function get(string $email, string $listId)
// will return the one and only member array('id', ...) from Collection
return $result->all();
} catch (\Exception $e) {
return false;
return [];
}
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public function getInterests(string $listId): array

return $interests;
} catch (\Exception $e) {
return false;
return [];
}
}

Expand All @@ -120,7 +120,7 @@ protected function getInterestsForCategoryId(string $interestCategoryId, string
// will return the one and only member array('id', ...) from Collection
return $result->all();
} catch (\Exception $e) {
return false;
return [];
}
}

Expand Down Expand Up @@ -208,22 +208,26 @@ public function subscribe(
$parameters['interests'] = $interestsObject;
}

return $this->api->request(
$this->api->request(
'lists/' . $listId . '/members/' . $this->getHashedEmail($email),
$parameters,
'put'
);

return true;
}

public function unsubscribe(string $email, string $listId): bool
{
return $this->api->request(
$this->api->request(
'lists/' . $listId . '/members/' . $this->getHashedEmail($email),
array(
'status' => 'unsubscribed',
),
'patch'
);

return true;
}

protected function getHashedEmail($email): string
Expand Down

0 comments on commit 4b5c4ac

Please sign in to comment.