key($label); if ($key===''||mb_strlen($label)>80||($productTitle!==''&&$key===$this->key($productTitle))) continue; $labels[$key]??=$label; } return array_values($labels); } public function key(string $value): string { $value=function_exists('remove_accents')?remove_accents($value):strtr($value,['À'=>'A','à'=>'a','É'=>'E','é'=>'e','’'=>"'"]); $value=function_exists('mb_strtolower')?mb_strtolower($value,'UTF-8'):strtolower($value); return preg_replace('/[^a-z0-9]+/u','',$value)??''; } public function brands(ProductDTO $product): array { $values=[]; foreach($product->getAttributes() as $attribute){if($attribute instanceof AttributeDTO&&in_array(strtolower(trim($attribute->getName())),['brand','marchio'],true)){$values=array_merge($values,$this->split($attribute->getValue(),$product->getName()));}} $unique=[]; foreach($values as $label){$unique[$this->key($label)]??=$label;} return array_values($unique); } public function matches(ProductDTO $product,string $selected):bool { $key=$this->key($selected); foreach($this->brands($product) as $brand){if($this->key($brand)===$key)return true;} return false; } }