getSelectedRooms(); // Check that at least one room is selected if (0 === count($selectedRooms)) { $this->context->buildViolation($constraint->noRoomSelectedMessage) ->addViolation(); return; } // Check that not only Baby rooms are selected $this->assertNotOnlyBabyRooms($value, $constraint); } private function assertNotOnlyBabyRooms(BookingDto $bookingDto, RoomSelection $constraint): void { $availableRooms = $bookingDto->travel->getAvailableRooms(); $selectedRooms = $bookingDto->getSelectedRooms(); $hasRegularRoom = false; $hasBabyRoom = false; foreach ($selectedRooms as $roomSelection) { $room = $availableRooms[$roomSelection->id] ?? null; if (null === $room) { continue; } if (Constants::BABY_ROOM_CODE === $room->code) { $hasBabyRoom = true; } else { $hasRegularRoom = true; } } if ($hasBabyRoom && false === $hasRegularRoom) { $this->context->buildViolation($constraint->onlyBabyRoomsMessage) ->addViolation(); } } }