chore: fix phpstan errors
This commit is contained in:
@@ -8,6 +8,7 @@ use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Utility\DirectionMapper;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
|
||||
/**
|
||||
* Calculates dynamic service availability based on current booking selections.
|
||||
@@ -52,11 +53,11 @@ class ServiceAvailabilityCalculator
|
||||
/**
|
||||
* Filter services array to only include those with remaining availability.
|
||||
*
|
||||
* @param array $services Array of Service objects to filter
|
||||
* @param BookingDto $bookingDto The booking data with participant selections
|
||||
* @param int $participantIndex The index of the participant currently filling the form
|
||||
* @param array<int, Service> $services Array of Service objects to filter
|
||||
* @param BookingDto $bookingDto The booking data with participant selections
|
||||
* @param int $participantIndex The index of the participant currently filling the form
|
||||
*
|
||||
* @return array Filtered array containing only available services
|
||||
* @return array<int, Service> Filtered array containing only available services
|
||||
*/
|
||||
public function filterAvailableServices(array $services, BookingDto $bookingDto, int $participantIndex): array
|
||||
{
|
||||
@@ -139,7 +140,11 @@ class ServiceAvailabilityCalculator
|
||||
}
|
||||
|
||||
// Count service selections for this participant
|
||||
$this->countParticipantServiceUsage($participant, $serviceUsage);
|
||||
$participantUsage = $this->countParticipantServiceUsage($participant);
|
||||
|
||||
foreach ($participantUsage as $serviceId => $count) {
|
||||
$serviceUsage[$serviceId] = ($serviceUsage[$serviceId] ?? 0) + $count;
|
||||
}
|
||||
}
|
||||
|
||||
return $serviceUsage;
|
||||
@@ -148,56 +153,57 @@ class ServiceAvailabilityCalculator
|
||||
/**
|
||||
* Count service usage for a single participant and add to the usage array.
|
||||
*
|
||||
* @param mixed $participant The participant DTO object
|
||||
* @param array $serviceUsage Reference to the service usage array to update
|
||||
* @param ParticipantDto $participant The participant DTO object
|
||||
*
|
||||
* @return array<int, int> Usage counts keyed by service ID
|
||||
*/
|
||||
private function countParticipantServiceUsage($participant, array &$serviceUsage): void
|
||||
private function countParticipantServiceUsage(ParticipantDto $participant): array
|
||||
{
|
||||
$serviceUsage = [];
|
||||
|
||||
// Board service (single selection)
|
||||
if (isset($participant->board) && $participant->board instanceof Service) {
|
||||
$serviceUsage[$participant->board->id] = ($serviceUsage[$participant->board->id] ?? 0) + 1;
|
||||
foreach ($participant->board as $service) {
|
||||
if (null !== $service->id) {
|
||||
$serviceUsage[$service->id] = ($serviceUsage[$service->id] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Ski pass service (single selection)
|
||||
if (isset($participant->skiPass) && $participant->skiPass instanceof Service) {
|
||||
if (null !== $participant->skiPass && null !== $participant->skiPass->id) {
|
||||
$serviceUsage[$participant->skiPass->id] = ($serviceUsage[$participant->skiPass->id] ?? 0) + 1;
|
||||
}
|
||||
|
||||
// Transportation services (single selection each)
|
||||
if (isset($participant->transportationOutbound) && $participant->transportationOutbound instanceof Service) {
|
||||
if (null !== $participant->transportationOutbound && null !== $participant->transportationOutbound->id) {
|
||||
$serviceUsage[$participant->transportationOutbound->id] = ($serviceUsage[$participant->transportationOutbound->id] ?? 0) + 1;
|
||||
}
|
||||
|
||||
if (isset($participant->transportationInbound) && $participant->transportationInbound instanceof Service) {
|
||||
if (null !== $participant->transportationInbound && null !== $participant->transportationInbound->id) {
|
||||
$serviceUsage[$participant->transportationInbound->id] = ($serviceUsage[$participant->transportationInbound->id] ?? 0) + 1;
|
||||
}
|
||||
|
||||
// Courses (multiple selection)
|
||||
if (isset($participant->courses) && is_array($participant->courses)) {
|
||||
foreach ($participant->courses as $course) {
|
||||
if ($course instanceof Service) {
|
||||
$serviceUsage[$course->id] = ($serviceUsage[$course->id] ?? 0) + 1;
|
||||
}
|
||||
foreach ($participant->courses as $course) {
|
||||
if (null !== $course->id) {
|
||||
$serviceUsage[$course->id] = ($serviceUsage[$course->id] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Additional services (multiple selection)
|
||||
if (isset($participant->additionalServices) && is_array($participant->additionalServices)) {
|
||||
foreach ($participant->additionalServices as $additionalService) {
|
||||
if ($additionalService instanceof Service) {
|
||||
$serviceUsage[$additionalService->id] = ($serviceUsage[$additionalService->id] ?? 0) + 1;
|
||||
}
|
||||
foreach ($participant->additionalServices as $additionalService) {
|
||||
if (null !== $additionalService->id) {
|
||||
$serviceUsage[$additionalService->id] = ($serviceUsage[$additionalService->id] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Rentals (multiple selection)
|
||||
if (isset($participant->rentals) && is_array($participant->rentals)) {
|
||||
foreach ($participant->rentals as $rental) {
|
||||
if ($rental instanceof Service) {
|
||||
$serviceUsage[$rental->id] = ($serviceUsage[$rental->id] ?? 0) + 1;
|
||||
}
|
||||
foreach ($participant->rentals as $rental) {
|
||||
if (null !== $rental->id) {
|
||||
$serviceUsage[$rental->id] = ($serviceUsage[$rental->id] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return $serviceUsage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,8 +219,8 @@ class ServiceAvailabilityCalculator
|
||||
|
||||
// Get all transportation services
|
||||
$transportationServices = array_merge(
|
||||
$bookingDto->travel->getTransportationServicesByDirection(DirectionMapper::OUTBOUND_TRAVEL) ?? [],
|
||||
$bookingDto->travel->getTransportationServicesByDirection(DirectionMapper::INBOUND_TRAVEL) ?? []
|
||||
$bookingDto->travel->getTransportationServicesByDirection(DirectionMapper::OUTBOUND_TRAVEL),
|
||||
$bookingDto->travel->getTransportationServicesByDirection(DirectionMapper::INBOUND_TRAVEL)
|
||||
);
|
||||
$allServices = array_merge($allServices, $transportationServices);
|
||||
|
||||
@@ -228,7 +234,7 @@ class ServiceAvailabilityCalculator
|
||||
];
|
||||
|
||||
foreach ($additionalServiceTokens as $token) {
|
||||
$categoryServices = $bookingDto->travel->getAdditionalServicesBySubTypes($token) ?? [];
|
||||
$categoryServices = $bookingDto->travel->getAdditionalServicesBySubTypes($token);
|
||||
$allServices = array_merge($allServices, $categoryServices);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user