35 lines
840 B
PHP
35 lines
840 B
PHP
<?php
|
|
|
|
namespace Domain\Normalizer\Decorator;
|
|
|
|
class PricewatchDecorator extends NormalizerDecorator
|
|
{
|
|
public function makePass(array $normalized): array
|
|
{
|
|
$module = $normalized['module'] ?? '-';
|
|
$module = $this->selectSignificantTerms($module);
|
|
|
|
$normalized['pricewatch_url'] = sprintf(
|
|
'https://tweakers.net/pricewatch/zoeken/?keyword=%s',
|
|
rawurlencode($module)
|
|
);
|
|
|
|
return $normalized;
|
|
}
|
|
|
|
protected function getAdditionalHeaders(): array
|
|
{
|
|
return ['pricewatch_url'];
|
|
}
|
|
|
|
private function selectSignificantTerms(string $module): string
|
|
{
|
|
$parts = explode(' ', trim($module), 2);
|
|
if ((count($parts) === 2) && stripos($parts[1], 'ver') !== false) {
|
|
return $parts[0];
|
|
}
|
|
|
|
return $module;
|
|
}
|
|
}
|