feat: refactor participant card DTOs and labels
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\BusProNet\Model\Service;
|
||||
|
||||
/**
|
||||
* Formats service labels for form and UI display.
|
||||
*/
|
||||
final class ServiceLabelFormatter
|
||||
{
|
||||
public function formatServiceLabel(Service $service): string
|
||||
{
|
||||
$label = $service->label ?? '';
|
||||
|
||||
if (null === $service->price) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
if (0.0 === $service->price) {
|
||||
return sprintf('%s (inkl.)', $label);
|
||||
}
|
||||
|
||||
if ($service->price < 0) {
|
||||
return sprintf('%s (-%s€ Rabatt)', $label, number_format(abs($service->price), 2, ',', '.'));
|
||||
}
|
||||
|
||||
return sprintf('%s (€%s)', $label, number_format($service->price, 2, ',', '.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, Service> $services
|
||||
*/
|
||||
public function formatServiceLabelForServices(string $fallbackLabel, array $services): string
|
||||
{
|
||||
$service = reset($services);
|
||||
if (false === $service) {
|
||||
return $fallbackLabel;
|
||||
}
|
||||
|
||||
if (!($service instanceof Service)) {
|
||||
return $fallbackLabel;
|
||||
}
|
||||
|
||||
return $this->formatServiceLabel($service);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user