fix: avoid null pointer exceptions, log warning about removed services
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\BusProNet\DataProcessor;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Processes participant service selections for booking updates.
|
||||
@@ -17,6 +18,11 @@ use App\Form\Model\ParticipantDto;
|
||||
*/
|
||||
class ParticipantServiceProcessor
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all existing participant-to-service mappings to start with a clean slate.
|
||||
*
|
||||
@@ -154,11 +160,18 @@ class ParticipantServiceProcessor
|
||||
foreach ($servicesToMap as $service) {
|
||||
if (false === isset($bookingData->additionalServices[$service->id])) {
|
||||
$serviceToAdd = $travelData->additionalServices[$service->id] ?? null;
|
||||
if (null !== $serviceToAdd) {
|
||||
$bookingData->additionalServices[$service->id] = $serviceToAdd;
|
||||
$bookingData->additionalServices[$service->id]->individualPrice[$participant->index] = $serviceToAdd->price;
|
||||
if (null === $serviceToAdd) {
|
||||
$this->logger->warning('Additional service not found in travel data, skipping mapping', [
|
||||
'bookingId' => $bookingData->id,
|
||||
'serviceId' => $service->id,
|
||||
'participantIndex' => $participant->index,
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
$bookingData->additionalServices[$service->id] = $serviceToAdd;
|
||||
$bookingData->additionalServices[$service->id]->individualPrice[$participant->index] = $serviceToAdd->price;
|
||||
}
|
||||
|
||||
$bookingData->additionalServices[$service->id]->mapping[] = $participant->index;
|
||||
}
|
||||
}
|
||||
@@ -176,13 +189,24 @@ class ParticipantServiceProcessor
|
||||
private function processTransportationServices(ParticipantDto $participant, Booking $bookingData, Travel $travelData): void
|
||||
{
|
||||
foreach ([$participant->transportationOutbound, $participant->transportationInbound] as $service) {
|
||||
if (null === $service) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false === isset($bookingData->transportationServices[$service->id])) {
|
||||
$serviceToAdd = $travelData->transportationServices[$service->id] ?? null;
|
||||
if (null !== $serviceToAdd) {
|
||||
$bookingData->transportationServices[$service->id] = $serviceToAdd;
|
||||
$bookingData->transportationServices[$service->id]->individualPrice[$participant->index] = $serviceToAdd->price;
|
||||
if (null === $serviceToAdd) {
|
||||
$this->logger->warning('Transportation service not found in travel data, skipping mapping', [
|
||||
'bookingId' => $bookingData->id,
|
||||
'serviceId' => $service->id,
|
||||
'participantIndex' => $participant->index,
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
$bookingData->transportationServices[$service->id] = $serviceToAdd;
|
||||
$bookingData->transportationServices[$service->id]->individualPrice[$participant->index] = $serviceToAdd->price;
|
||||
}
|
||||
|
||||
$bookingData->transportationServices[$service->id]->mapping[] = $participant->index;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user