33 lines
846 B
PHP
33 lines
846 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Station;
|
|
|
|
class StationTaggingService
|
|
{
|
|
/** @var array<string, string> brand keyword → normalised brand name */
|
|
private const SUPERMARKET_BRANDS = [
|
|
'tesco' => 'Tesco',
|
|
'asda' => 'Asda',
|
|
'morrisons' => 'Morrisons',
|
|
'sainsbury' => 'Sainsbury\'s',
|
|
'aldi' => 'Aldi',
|
|
'lidl' => 'Lidl',
|
|
'costco' => 'Costco',
|
|
];
|
|
|
|
public function tag(Station $station): void
|
|
{
|
|
$name = strtolower($station->trading_name);
|
|
|
|
foreach (self::SUPERMARKET_BRANDS as $keyword => $normalisedBrand) {
|
|
if (str_contains($name, $keyword)) {
|
|
$station->is_supermarket = true;
|
|
$station->brand_name = $normalisedBrand;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|