applicantInsuranceChosenWhileFamilyIneligible) { return false; } $applicant = $bookingDto->getParticipant(0); if (null === $applicant || null === $applicant->insurance || true === $applicant->insurance->familyInsurance) { return false; } return $this->hasEligibleFamilyInsurance($bookingDto); } /** * Checks whether a family insurance is actually eligible right now - not just whether * the participant composition qualifies as a family booking, but whether a selectable * family insurance product actually matches the current total booking price. */ public function hasEligibleFamilyInsurance(BookingDto $bookingDto): bool { if (false === $bookingDto->isFamilyBooking()) { return false; } $applicant = $bookingDto->getParticipant(0); if (null === $applicant) { return false; } $selectableInsurances = $this->insuranceService->getSelectableInsurances($bookingDto->travel); $familyInsurances = array_values(array_filter($selectableInsurances, static fn (Insurance $i) => true === $i->familyInsurance)); if ([] === $familyInsurances) { return false; } $totalPrice = $this->priceCalculatorService->calculateTotalBookingPriceExcludingInsurance($bookingDto); return [] !== $this->insuranceService->getEligibleInsurances($familyInsurances, $applicant, $bookingDto, $totalPrice); } }