feat: refactor participant card DTOs and labels

This commit is contained in:
Björn Fromme
2026-04-11 18:28:32 +02:00
parent f22ceae41c
commit 1b0e479e49
10 changed files with 299 additions and 139 deletions
+49
View File
@@ -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);
}
}