diff --git a/src/admin/library/Free/MailingList/MailChimp.php b/src/admin/library/Free/MailingList/MailChimp.php index 74b3c94d..65117a29 100644 --- a/src/admin/library/Free/MailingList/MailChimp.php +++ b/src/admin/library/Free/MailingList/MailChimp.php @@ -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; } /**