feat: refactoring and cleanup
This commit is contained in:
@@ -33,6 +33,8 @@ class AcceptedVouchersDto
|
||||
|
||||
/**
|
||||
* @return array<AcceptedVoucherDto>
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getPromotionalVouchers(): array
|
||||
{
|
||||
@@ -41,6 +43,8 @@ class AcceptedVouchersDto
|
||||
|
||||
/**
|
||||
* @return array<AcceptedVoucherDto>
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getPurchaseVouchers(): array
|
||||
{
|
||||
@@ -49,6 +53,8 @@ class AcceptedVouchersDto
|
||||
|
||||
/**
|
||||
* @return array<AcceptedVoucherDto>
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getGoodwillVouchers(): array
|
||||
{
|
||||
@@ -65,6 +71,9 @@ class AcceptedVouchersDto
|
||||
return count($this->vouchers) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->vouchers);
|
||||
|
||||
@@ -46,6 +46,8 @@ class BankAccountDto
|
||||
|
||||
/**
|
||||
* Returns IBAN formatted with spaces for display (e.g., DE12 3456 7890 1234 5678 90).
|
||||
*
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function getFormattedIban(): ?string
|
||||
{
|
||||
@@ -60,6 +62,8 @@ class BankAccountDto
|
||||
|
||||
/**
|
||||
* Returns IBAN without spaces for storage and API submission.
|
||||
*
|
||||
* @deprecated Only used by getFormattedIban() which is also deprecated
|
||||
*/
|
||||
public function getIbanWithoutSpaces(): ?string
|
||||
{
|
||||
|
||||
@@ -161,6 +161,9 @@ class BookingDto
|
||||
return $this->participants;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use getParticipant() and check for null instead
|
||||
*/
|
||||
public function hasParticipant(int $index): bool
|
||||
{
|
||||
return isset($this->participants[$index]);
|
||||
@@ -202,11 +205,17 @@ class BookingDto
|
||||
return ($adults >= 1 && $adults <= 2) && ($children >= 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ParticipantDto::isCanceled() instead
|
||||
*/
|
||||
public function isCanceled(): bool
|
||||
{
|
||||
return null !== $this->booking && 'S' === $this->booking->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use ParticipantDto::isOption() instead
|
||||
*/
|
||||
public function isOption(): bool
|
||||
{
|
||||
return null !== $this->booking && 'O' === $this->booking->status;
|
||||
@@ -219,6 +228,8 @@ class BookingDto
|
||||
* Used by templates to display the room assignment when the dropdown is hidden.
|
||||
*
|
||||
* @return string|null The room label or null if not a single room type scenario
|
||||
*
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function getSingleRoomLabel(): ?string
|
||||
{
|
||||
@@ -284,6 +295,8 @@ class BookingDto
|
||||
* Checks if any participants have entered voucher codes.
|
||||
*
|
||||
* @return bool True if any promotional, purchase, or goodwill vouchers are present
|
||||
*
|
||||
* @deprecated Use AcceptedVouchersDto::hasVouchers() instead
|
||||
*/
|
||||
public function hasVouchers(): bool
|
||||
{
|
||||
@@ -317,4 +330,61 @@ class BookingDto
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the number of participants assigned to each room ID.
|
||||
*
|
||||
* @return array<int, int> Array where key is room ID and value is count of assigned participants
|
||||
*/
|
||||
public function getRoomAssignmentCounts(): array
|
||||
{
|
||||
$counts = [];
|
||||
foreach ($this->participants as $participant) {
|
||||
if (null !== $participant->assignedRoomId) {
|
||||
$counts[$participant->assignedRoomId] = ($counts[$participant->assignedRoomId] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $counts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all participant room assignments.
|
||||
*
|
||||
* Clears room assignments when room selections change to prevent
|
||||
* invalid assignments.
|
||||
*/
|
||||
public function resetParticipantAssignments(): void
|
||||
{
|
||||
foreach ($this->participants as $participant) {
|
||||
$participant->assignedRoomId = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a snapshot of the current room selection state.
|
||||
*
|
||||
* @return array<int, array{int, int}> Array of [roomId, quantity] pairs
|
||||
*/
|
||||
public function createRoomSelectionSnapshot(): array
|
||||
{
|
||||
return array_map(
|
||||
fn ($roomSelection) => [(int) $roomSelection->roomId, (int) $roomSelection->quantity],
|
||||
$this->roomSelections
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if room selection has changed compared to a previous snapshot.
|
||||
*
|
||||
* @param array<int, array{int, int}> $oldSnapshot The baseline room selection snapshot
|
||||
*
|
||||
* @return bool True if room selections have changed, false otherwise
|
||||
*/
|
||||
public function hasRoomSelectionChanged(array $oldSnapshot): bool
|
||||
{
|
||||
$newSnapshot = $this->createRoomSelectionSnapshot();
|
||||
|
||||
return $oldSnapshot !== $newSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
/**
|
||||
* DTO containing all booking summary data for sidebar display.
|
||||
*
|
||||
* Provides pricing breakdowns, room assignments, participant counts,
|
||||
* and CMS product information in a single typed object.
|
||||
*/
|
||||
class BookingSummaryDto
|
||||
{
|
||||
/**
|
||||
* @param array<int, RoomSelectionDto> $selectedRooms Selected room DTOs from booking
|
||||
* @param int $participantCount Total participant count from room capacity
|
||||
* @param string $totalPrice Formatted total price (e.g., "1.234,56 €")
|
||||
* @param array<array{room: mixed, count: int}> $groupedSelectedRooms Rooms grouped by participant assignments
|
||||
* @param array<int, int> $assignmentCounts Room ID to participant count mapping
|
||||
* @param array $pricingData Detailed pricing breakdown
|
||||
* @param array|null $cmsData CMS product data (images, etc.)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $selectedRooms,
|
||||
public readonly int $participantCount,
|
||||
public readonly string $totalPrice,
|
||||
public readonly array $groupedSelectedRooms,
|
||||
public readonly array $assignmentCounts,
|
||||
public readonly array $pricingData,
|
||||
public readonly ?array $cmsData,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -207,6 +207,9 @@ class ParticipantDto
|
||||
return 'S' === $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated No known usages
|
||||
*/
|
||||
public function isOption(): bool
|
||||
{
|
||||
return 'O' === $this->status;
|
||||
@@ -237,6 +240,8 @@ class ParticipantDto
|
||||
* Checks if the participant has selected an insurance.
|
||||
*
|
||||
* @return bool True if an insurance is selected
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function hasInsuranceSelected(): bool
|
||||
{
|
||||
@@ -247,6 +252,8 @@ class ParticipantDto
|
||||
* Gets the insurance label for display purposes.
|
||||
*
|
||||
* @return string|null The insurance label or null if no insurance selected
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getInsuranceLabel(): ?string
|
||||
{
|
||||
@@ -257,6 +264,8 @@ class ParticipantDto
|
||||
* Gets the insurance price for pricing calculations.
|
||||
*
|
||||
* @return float The insurance price (0.0 if no insurance selected)
|
||||
*
|
||||
* @deprecated No known usages outside tests
|
||||
*/
|
||||
public function getInsurancePrice(): float
|
||||
{
|
||||
|
||||
@@ -182,4 +182,33 @@ abstract class AbstractParticipantFieldHandler implements ParticipantFieldHandle
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds an item by ID from an array of objects.
|
||||
*
|
||||
* Generic helper for validating a selected ID against an array of available
|
||||
* items and returning the matching object. Used by handlers that need to
|
||||
* validate service, pickup, or other selections against available options.
|
||||
*
|
||||
* @param mixed $selectedId The submitted ID to find (string or int)
|
||||
* @param object[] $items Array of objects with an `id` property
|
||||
*
|
||||
* @return object|null The matching item, or null if not found or invalid ID
|
||||
*/
|
||||
protected function findItemById(mixed $selectedId, array $items): ?object
|
||||
{
|
||||
if (null === $selectedId || (false === is_string($selectedId) && false === is_int($selectedId))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$id = (int) $selectedId;
|
||||
|
||||
foreach ($items as $item) {
|
||||
if ($item->id === $id) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
@@ -58,36 +57,6 @@ class ParticipantPickupFieldHandler extends AbstractParticipantFieldHandler
|
||||
$selectedPickup = $this->getFieldValue($submittedData, $this->getFieldName());
|
||||
|
||||
// Validate pickup selection against available outbound pickups
|
||||
$validSelection = null;
|
||||
if (null !== $selectedPickup) {
|
||||
$validSelection = $this->findValidPickup($selectedPickup, $bookingDto->travel->pickupsOutbound);
|
||||
}
|
||||
|
||||
$participant->pickup = $validSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a valid pickup from available pickups.
|
||||
*
|
||||
* @param mixed $selectedPickupId The submitted pickup ID
|
||||
* @param array<int, Pickup> $availablePickups Array of available pickup locations
|
||||
*
|
||||
* @return Pickup|null The valid pickup object, or null if invalid
|
||||
*/
|
||||
private function findValidPickup(mixed $selectedPickupId, array $availablePickups): ?Pickup
|
||||
{
|
||||
if (null === $selectedPickupId || false === is_string($selectedPickupId) && false === is_int($selectedPickupId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$pickupId = (int) $selectedPickupId;
|
||||
|
||||
foreach ($availablePickups as $pickup) {
|
||||
if ($pickup->id === $pickupId) {
|
||||
return $pickup;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
$participant->pickup = $this->findItemById($selectedPickup, $bookingDto->travel->pickupsOutbound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
@@ -57,43 +56,7 @@ class ParticipantTransportationInboundFieldHandler extends AbstractParticipantFi
|
||||
true // filter available
|
||||
);
|
||||
|
||||
// Validate and convert selection to Service object
|
||||
$validSelection = null;
|
||||
if (null !== $selectedTransportation) {
|
||||
$validSelection = $this->findValidTransportationService(
|
||||
$selectedTransportation,
|
||||
$availableServices
|
||||
);
|
||||
}
|
||||
|
||||
// Update participant with validated selection
|
||||
$participant->transportationInbound = $validSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a valid transportation service from available services.
|
||||
*
|
||||
* @param mixed $selectedServiceId The submitted service ID
|
||||
* @param array<int, Service> $availableServices Array of available transportation services
|
||||
*
|
||||
* @return Service|null The valid service object, or null if invalid
|
||||
*/
|
||||
private function findValidTransportationService(
|
||||
mixed $selectedServiceId,
|
||||
array $availableServices,
|
||||
): ?Service {
|
||||
if (null === $selectedServiceId || false === is_string($selectedServiceId) && false === is_int($selectedServiceId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$serviceId = (int) $selectedServiceId;
|
||||
|
||||
foreach ($availableServices as $service) {
|
||||
if ($service->id === $serviceId) {
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// Validate and update participant with selection
|
||||
$participant->transportationInbound = $this->findItemById($selectedTransportation, $availableServices);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
@@ -57,43 +56,7 @@ class ParticipantTransportationOutboundFieldHandler extends AbstractParticipantF
|
||||
true // filter available
|
||||
);
|
||||
|
||||
// Validate and convert selection to Service object
|
||||
$validSelection = null;
|
||||
if (null !== $selectedTransportation) {
|
||||
$validSelection = $this->findValidTransportationService(
|
||||
$selectedTransportation,
|
||||
$availableServices
|
||||
);
|
||||
}
|
||||
|
||||
// Update participant with validated selection
|
||||
$participant->transportationOutbound = $validSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a valid transportation service from available services.
|
||||
*
|
||||
* @param mixed $selectedServiceId The submitted service ID
|
||||
* @param array<int, Service> $availableServices Array of available transportation services
|
||||
*
|
||||
* @return Service|null The valid service object, or null if invalid
|
||||
*/
|
||||
private function findValidTransportationService(
|
||||
mixed $selectedServiceId,
|
||||
array $availableServices,
|
||||
): ?Service {
|
||||
if (null === $selectedServiceId || false === is_string($selectedServiceId) && false === is_int($selectedServiceId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$serviceId = (int) $selectedServiceId;
|
||||
|
||||
foreach ($availableServices as $service) {
|
||||
if ($service->id === $serviceId) {
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
// Validate and update participant with selection
|
||||
$participant->transportationOutbound = $this->findItemById($selectedTransportation, $availableServices);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user