$config */ public function __construct(private readonly array $config) { } /** * @return string[] */ public function getStopWords(): array { return $this->requiredStringList('words'); } /** * @return string[] */ private function requiredStringList(string $key): array { if (!array_key_exists($key, $this->config)) { throw new \InvalidArgumentException(sprintf('Missing required RetrieX stopwords config key "%s".', $key)); } $value = $this->config[$key]; if (!is_array($value)) { throw new \InvalidArgumentException(sprintf('RetrieX stopwords config key "%s" must be a list.', $key)); } $out = []; foreach ($value as $item) { if (!is_scalar($item)) { continue; } $item = trim((string) $item); if ($item === '') { continue; } if (!in_array($item, $out, true)) { $out[] = $item; } } if ($out === []) { throw new \InvalidArgumentException(sprintf('RetrieX stopwords config key "%s" must not be empty.', $key)); } return $out; } }