Skip to content

Commit

Permalink
Always return the ApiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
billtomczak committed Apr 5, 2024
1 parent 97de0fd commit 8183eb8
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/admin/library/Free/MailingList/MailChimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,26 @@ public function onTableAfterStore(Event $event): void
}

/**
* @return ?ApiClient
* @return ApiClient
*/
public static function getMailChimp(): ?ApiClient
public static function getMailChimp(): ApiClient
{
if (static::$apiManager === null) {
static::$apiManager = false;
try {
$params = static::getParams();
$apiKey = $params->get('mailinglist.mailchimp.api', 0);
if ($apiKey) {
[$apikey, $server] = explode('-', $apiKey);
static::$apiManager = new ApiClient();
static::$apiManager->setConfig([
'apiKey' => $apiKey,
'server' => $server,
]);
}

} catch (\Throwable $e) {
// Just ignore this
static::$apiManager = new ApiClient();

$params = static::getParams();
$api = $params->get('mailinglist.mailchimp.api');
if ($api && str_contains($api, '-')) {
[$apiKey, $server] = explode('-', $api, 2);
static::$apiManager = new ApiClient();
static::$apiManager->setConfig([
'apiKey' => $apiKey,
'server' => $server,
]);
}
}

return static::$apiManager ?: null;
return static::$apiManager;
}

/**
Expand Down

0 comments on commit 8183eb8

Please sign in to comment.