From 4b7afb109dfc64deb9478dd271c307a318ab4a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 12 Oct 2023 15:08:47 +0200 Subject: [PATCH] Fix: Make country name filter failure tolerant --- src/BusProNet/DataProvider/CountryDataProvider.php | 6 +++++- src/Twig/AppRuntime.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/BusProNet/DataProvider/CountryDataProvider.php b/src/BusProNet/DataProvider/CountryDataProvider.php index 4f884c4..00621a7 100644 --- a/src/BusProNet/DataProvider/CountryDataProvider.php +++ b/src/BusProNet/DataProvider/CountryDataProvider.php @@ -32,8 +32,12 @@ class CountryDataProvider return $countries; } - public function get(string $token): ?Country + public function get(?string $token): ?Country { + if (null === $token) { + return null; + } + return $this->getAll()[$token] ?? null; } } \ No newline at end of file diff --git a/src/Twig/AppRuntime.php b/src/Twig/AppRuntime.php index 42ebeda..566b82a 100644 --- a/src/Twig/AppRuntime.php +++ b/src/Twig/AppRuntime.php @@ -36,7 +36,7 @@ class AppRuntime implements RuntimeExtensionInterface return sprintf('Offizielle %slehrer*innenlizenz', ucfirst(strtolower($type))); } - public function bpnCountryLabel(string $token, string $property = 'name'): string + public function bpnCountryLabel(?string $token, string $property = 'name'): string { $country = $this->countries->get($token);