country code → terms document URL */ private array $termsUrls; /** * @param array $config */ public function __construct( array $config, private readonly string $termsAndConditionsUrl, ) { $this->termsUrls = $this->resolveConfig($config); } public function forAccommodation(?Accommodation $accommodation): string { $country = $accommodation?->getCountry(); $url = null !== $country ? ($this->termsUrls[$country->value] ?? '') : ''; return '' !== $url ? $url : $this->termsAndConditionsUrl; } /** * @param array $config * * @return array */ private function resolveConfig(array $config): array { $resolver = new OptionsResolver(); $resolver->setRequired(['AT', 'CH', 'IT']); $resolver->setAllowedTypes('AT', 'string'); $resolver->setAllowedTypes('CH', 'string'); $resolver->setAllowedTypes('IT', 'string'); return $resolver->resolve($config); } }