feat: split summary DTOs into typed sub-objects
This commit is contained in:
@@ -4,22 +4,19 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
|
||||
/**
|
||||
* Bundles the data needed to render the booking create flow.
|
||||
*/
|
||||
class BookingCreateContext
|
||||
{
|
||||
/**
|
||||
* @param array{by_pax: array<int, Room>, by_room: array<int, Room>} $groupedRooms
|
||||
* @param array<int, ParticipantCardDataDto>|null $cardsData
|
||||
* @param array<int, float>|null $participantPrices
|
||||
* @param array<int, ParticipantCardDataDto>|null $cardsData
|
||||
* @param array<int, float>|null $participantPrices
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly BookingDto $bookingDto,
|
||||
public readonly BookingSummaryDto $summaryData,
|
||||
public readonly array $groupedRooms,
|
||||
public readonly RoomGroupsDto $groupedRooms,
|
||||
public readonly ?array $cardsData = null,
|
||||
public readonly bool $isSubmitted = false,
|
||||
public readonly ?array $participantPrices = null,
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Booking;
|
||||
|
||||
/**
|
||||
@@ -18,7 +17,7 @@ class BookingEditContext
|
||||
public function __construct(
|
||||
public readonly BookingDto $bookingDto,
|
||||
public readonly ?Booking $bookingData,
|
||||
public readonly ?BaseData $mutableData,
|
||||
public readonly ?BookingMutabilityDto $mutableData,
|
||||
public readonly BookingSummaryDto $summaryData,
|
||||
public readonly ?array $cardsData = null,
|
||||
public readonly bool $isDirty = false,
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\MutableData;
|
||||
|
||||
/**
|
||||
* Typed wrapper for edit-mode mutability data.
|
||||
*/
|
||||
final class BookingMutabilityDto
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ?MutableData $participantCount,
|
||||
public readonly ?MutableData $participantData,
|
||||
public readonly ?MutableData $transportation,
|
||||
public readonly ?MutableData $pickup,
|
||||
public readonly ?MutableData $accommodation,
|
||||
public readonly ?MutableData $additionalServices,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromBaseData(?BaseData $baseData): ?self
|
||||
{
|
||||
if (null === $baseData) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new self(
|
||||
participantCount: self::getItem($baseData, MutableData::CATEGORY_PARTICIPANT_COUNT),
|
||||
participantData: self::getItem($baseData, MutableData::CATEGORY_PARTICIPANT_DATA),
|
||||
transportation: self::getItem($baseData, MutableData::CATEGORY_TRANSPORTATION),
|
||||
pickup: self::getItem($baseData, MutableData::CATEGORY_PICKUP),
|
||||
accommodation: self::getItem($baseData, MutableData::CATEGORY_ACCOMMODATION),
|
||||
additionalServices: self::getItem($baseData, MutableData::CATEGORY_ADDITIONAL_SERVICES),
|
||||
);
|
||||
}
|
||||
|
||||
private static function getItem(BaseData $baseData, string $key): ?MutableData
|
||||
{
|
||||
$item = $baseData->getItemByKey($key);
|
||||
|
||||
return $item instanceof MutableData ? $item : null;
|
||||
}
|
||||
}
|
||||
@@ -6,30 +6,17 @@ 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 float $totalPrice Total price before voucher deductions
|
||||
* @param float $payableAmount Amount after voucher deductions
|
||||
* @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.)
|
||||
* @param array<int, RoomSelectionDto> $selectedRooms Selected room DTOs from booking
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $selectedRooms,
|
||||
public readonly int $participantCount,
|
||||
public readonly float $totalPrice,
|
||||
public readonly float $payableAmount,
|
||||
public readonly array $groupedSelectedRooms,
|
||||
public readonly array $assignmentCounts,
|
||||
public readonly array $pricingData,
|
||||
public readonly BookingSummaryPricingDto $pricing,
|
||||
public readonly BookingSummaryVoucherDto $vouchers,
|
||||
public readonly ?array $cmsData,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
/**
|
||||
* Typed pricing section for the booking summary.
|
||||
*/
|
||||
final class BookingSummaryPricingDto
|
||||
{
|
||||
/**
|
||||
* @param array<int, array<string, mixed>> $rooms
|
||||
* @param array<int, array<string, mixed>> $services
|
||||
* @param array<int, array<string, mixed>>|null $surcharges
|
||||
* @param array<int, int> $assignmentCounts
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $rooms,
|
||||
public readonly array $services,
|
||||
public readonly ?array $surcharges,
|
||||
public readonly array $assignmentCounts,
|
||||
public readonly float $grandTotal,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
/**
|
||||
* Typed voucher section for the booking summary.
|
||||
*/
|
||||
final class BookingSummaryVoucherDto
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ?AcceptedVouchersDto $acceptedVouchers,
|
||||
public readonly float $payableAmount,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Model;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
|
||||
/**
|
||||
* Typed room grouping used by the booking create flow.
|
||||
*/
|
||||
final class RoomGroupsDto
|
||||
{
|
||||
/**
|
||||
* @param array<int, Room> $byPax
|
||||
* @param array<int, Room> $byRoom
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly array $byPax,
|
||||
public readonly array $byRoom,
|
||||
) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user