chore: cgl fixes

This commit is contained in:
fromme committed 2026-09-11 19:37:00 +02:00
1 parent 5f8a586385
commit 5b133f724d
26 files changed
+87 -92

No files matched your search

+30 -30
View File
@@ -13,9 +13,9 @@ use App\Model\CalendarMonth;
use App\Service\AccommodationPriceCoverage;
use Carbon\CarbonImmutable;
use Psr\Cache\InvalidArgumentException;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent('calendar', template: 'components/calendar/index.html.twig')]
class Calendar
@@ -55,8 +55,8 @@ class Calendar
$this->accommodation = $accommodation;
$this->startMonth = $startMonth;
if ($startMonth !== null && preg_match('/^\d{4}-\d{2}$/', $startMonth)) {
$start = CarbonImmutable::createFromFormat('Y-m-d', $startMonth . '-01');
if (null !== $startMonth && preg_match('/^\d{4}-\d{2}$/', $startMonth)) {
$start = CarbonImmutable::createFromFormat('Y-m-d', $startMonth.'-01');
} else {
$allDates = $this->collectAllDates();
$start = empty($allDates)
@@ -73,7 +73,7 @@ class Calendar
$months = [];
$current = $start;
for ($i = 0; $i < 3; $i++) {
for ($i = 0; $i < 3; ++$i) {
$months[] = $this->buildMonth($current, $map, $blockedDates);
$current = $current->addMonth();
}
@@ -81,22 +81,22 @@ class Calendar
$this->months = $months;
$prevStart = $start->subMonths(3);
$prevEnd = $prevStart->addMonths(2);
$prevEnd = $prevStart->addMonths(2);
$this->prevMonth = $prevStart->format('Y-m');
$this->prevLabel = self::MONTHS[$prevStart->month] . ' – ' . self::MONTHS[$prevEnd->month] . ' ' . $prevEnd->year;
$this->prevLabel = self::MONTHS[$prevStart->month].' – '.self::MONTHS[$prevEnd->month].' '.$prevEnd->year;
$nextStart = $start->addMonths(3);
$nextEnd = $nextStart->addMonths(2);
$nextEnd = $nextStart->addMonths(2);
$this->nextMonth = $nextStart->format('Y-m');
$this->nextLabel = self::MONTHS[$nextStart->month] . ' – ' . self::MONTHS[$nextEnd->month] . ' ' . $nextEnd->year;
$this->nextLabel = self::MONTHS[$nextStart->month].' – '.self::MONTHS[$nextEnd->month].' '.$nextEnd->year;
}
/**
* @return array<string, true> keyed by Y-m-d, only BLOCKED dates present
* @return array<string, true> keyed by Y-m-d, only BLOCKED dates present
*/
private function fetchBlockedDates(string $hotelCode, string $dateFrom, string $dateTo): array
{
if ($hotelCode === '') {
if ('' === $hotelCode) {
return [];
}
@@ -116,7 +116,7 @@ class Calendar
$blocked = [];
foreach ($response->data as $entry) {
if ($entry->status === ContingentStatus::Blocked) {
if (ContingentStatus::Blocked === $entry->status) {
$blocked[(new \DateTimeImmutable($entry->date))->format('Y-m-d')] = true;
}
}
@@ -144,26 +144,26 @@ class Calendar
$dates = [];
foreach ($this->accommodation->getAccommodationPrices() as $price) {
if ($price->getDateFrom() !== null) {
if (null !== $price->getDateFrom()) {
$dates[] = CarbonImmutable::instance($price->getDateFrom());
}
if ($price->getDateTo() !== null) {
if (null !== $price->getDateTo()) {
$dates[] = CarbonImmutable::instance($price->getDateTo());
}
}
foreach ($this->accommodation->getBoardServices() as $service) {
if ($service->getDateFrom() !== null) {
if (null !== $service->getDateFrom()) {
$dates[] = CarbonImmutable::instance($service->getDateFrom());
}
if ($service->getDateTo() !== null) {
if (null !== $service->getDateTo()) {
$dates[] = CarbonImmutable::instance($service->getDateTo());
}
}
foreach ($this->accommodation->getAdditionalServices() as $service) {
if ($service->getDateFrom() !== null) {
if (null !== $service->getDateFrom()) {
$dates[] = CarbonImmutable::instance($service->getDateFrom());
}
if ($service->getDateTo() !== null) {
if (null !== $service->getDateTo()) {
$dates[] = CarbonImmutable::instance($service->getDateTo());
}
}
@@ -198,11 +198,11 @@ class Calendar
$map = [];
foreach ($this->accommodation->getAccommodationPrices() as $price) {
if ($price->getDateFrom() === null || $price->getDateTo() === null) {
if (null === $price->getDateFrom() || null === $price->getDateTo()) {
continue;
}
$priceFormatted = number_format($price->getPricePerNight() / 100, 2, ',', '.') . ' €';
$priceFormatted = number_format($price->getPricePerNight() / 100, 2, ',', '.').' €';
$label = sprintf('Preis: %s/Nacht (min. %d Nächte)', $priceFormatted, $price->getMinNights());
$day = CarbonImmutable::instance($price->getDateFrom());
@@ -216,7 +216,7 @@ class Calendar
$key = $day->format('Y-m-d');
$map[$key] ??= ['price' => null, 'board' => null, 'additional' => null];
$existing = $map[$key]['price'];
$replace = $existing === null
$replace = null === $existing
|| $priority > $existing['priority']
|| ($priority === $existing['priority'] && $span < $existing['span']);
if ($replace) {
@@ -227,11 +227,11 @@ class Calendar
}
foreach ($this->accommodation->getBoardServices() as $service) {
if ($service->getDateFrom() === null || $service->getDateTo() === null) {
if (null === $service->getDateFrom() || null === $service->getDateTo()) {
continue;
}
$label = 'Verpflegung: ' . $service->getLabel();
$label = 'Verpflegung: '.$service->getLabel();
$day = CarbonImmutable::instance($service->getDateFrom());
$end = CarbonImmutable::instance($service->getDateTo());
@@ -241,7 +241,7 @@ class Calendar
while ($day <= $end && $day <= $limit) {
$key = $day->format('Y-m-d');
$map[$key] ??= ['price' => null, 'board' => null, 'additional' => null];
if ($map[$key]['board'] === null || $span < $map[$key]['board']['span']) {
if (null === $map[$key]['board'] || $span < $map[$key]['board']['span']) {
$map[$key]['board'] = ['label' => $label, 'span' => $span];
}
$day = $day->addDay();
@@ -249,14 +249,14 @@ class Calendar
}
foreach ($this->accommodation->getAdditionalServices() as $service) {
if ($service->getDateFrom() === null || $service->getDateTo() === null) {
if (null === $service->getDateFrom() || null === $service->getDateTo()) {
continue;
}
$typeLabel = $service->getType() !== null
$typeLabel = null !== $service->getType()
? self::TYPE_LABELS[$service->getType()->value]
: '';
$label = sprintf('Zusatz: %s%s', $service->getLabel(), $typeLabel !== '' ? ' (' . $typeLabel . ')' : '');
$label = sprintf('Zusatz: %s%s', $service->getLabel(), '' !== $typeLabel ? ' ('.$typeLabel.')' : '');
$day = CarbonImmutable::instance($service->getDateFrom());
$end = CarbonImmutable::instance($service->getDateTo());
@@ -266,7 +266,7 @@ class Calendar
while ($day <= $end && $day <= $limit) {
$key = $day->format('Y-m-d');
$map[$key] ??= ['price' => null, 'board' => null, 'additional' => null];
if ($map[$key]['additional'] === null || $span < $map[$key]['additional']['span']) {
if (null === $map[$key]['additional'] || $span < $map[$key]['additional']['span']) {
$map[$key]['additional'] = ['label' => $label, 'span' => $span];
}
$day = $day->addDay();
@@ -293,8 +293,8 @@ class Calendar
$firstDow = ($start->dayOfWeek + 6) % 7;
$days = [];
for ($d = 1; $d <= $start->daysInMonth; $d++) {
$dateStr = $month->format('Y-m') . '-' . str_pad((string) $d, 2, '0', STR_PAD_LEFT);
for ($d = 1; $d <= $start->daysInMonth; ++$d) {
$dateStr = $month->format('Y-m').'-'.str_pad((string) $d, 2, '0', STR_PAD_LEFT);
$coverage = $map[$dateStr] ?? [];
$parts = [];
@@ -325,7 +325,7 @@ class Calendar
}
return new CalendarMonth(
label: self::MONTHS[$month->month] . ' ' . $month->year,
label: self::MONTHS[$month->month].' '.$month->year,
firstDow: $firstDow,
days: $days,
);