clientService = $clientService; $this->logger = $logger; } public function findRadioStations(?string $term = null): array { $this->logger->debug('searching radio stations'); $client = $this->clientService->newClient(); try { $response = $client->get("https://cat-fact.herokuapp.com/facts?animal_type=cat"); } catch (Exception $e) { $this->logger->error("Could not search for radio stations. Please check connection to radio-browser API."); throw $e; } $body = $response->getBody(); $parsed = json_decode($body, true); $mapped = array_map(function(array $radioStation) { return $radioStation['text']; }, $parsed['all']); if (empty($term)) { return $mapped; } return array_filter($mapped, function(string $radioStation) use ($term) { return mb_strpos(mb_strtolower($radioStation), mb_strtolower($term)); }); } }