fix: simplify trait to address incorrect arguments

This commit is contained in:
Björn Fromme
2026-03-28 10:18:34 +01:00
parent bca3610cff
commit fbfffbb31a
3 changed files with 23 additions and 35 deletions
@@ -76,13 +76,13 @@ class Step3Controller extends AbstractController
$inquiryResponse = $this->apiClient->createBookingInquiry($bookingCreateDto); $inquiryResponse = $this->apiClient->createBookingInquiry($bookingCreateDto);
if ($inquiryResponse instanceof Notification) { if ($inquiryResponse instanceof Notification) {
return $this->handleApiError( $this->handleApiError(
'Booking inquiry failed', 'Booking inquiry failed',
['message' => $inquiryResponse->message], ['message' => $inquiryResponse->message],
$inquiryResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuche es erneut oder wende dich an den Kundenservice.', $inquiryResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuche es erneut oder wende dich an den Kundenservice.',
$bookingCreateDto,
$form
); );
return $this->renderStepForm($bookingCreateDto, $form);
} }
if (false === $inquiryResponse->isInquiryValid()) { if (false === $inquiryResponse->isInquiryValid()) {
@@ -109,13 +109,13 @@ class Step3Controller extends AbstractController
$errorMessage .= ' '.$inquiryResponse->message; $errorMessage .= ' '.$inquiryResponse->message;
} }
return $this->handleApiError( $this->handleApiError(
'Booking inquiry validation failed', 'Booking inquiry validation failed',
['status' => $inquiryResponse->status, 'message' => $inquiryResponse->message], ['status' => $inquiryResponse->status, 'message' => $inquiryResponse->message],
$errorMessage, $errorMessage,
$bookingCreateDto,
$form
); );
return $this->renderStepForm($bookingCreateDto, $form);
} }
// Validate price match (rounded to cent precision to avoid floating-point errors) // Validate price match (rounded to cent precision to avoid floating-point errors)
@@ -133,7 +133,7 @@ class Step3Controller extends AbstractController
$diagnostics = $this->priceMismatchDiagnostics->buildDiagnostics($bookingCreateDto, $inquiryResponse); $diagnostics = $this->priceMismatchDiagnostics->buildDiagnostics($bookingCreateDto, $inquiryResponse);
$deltaBreakdown = $diagnostics['deltaBreakdown'] ?? []; $deltaBreakdown = $diagnostics['deltaBreakdown'] ?? [];
return $this->handleApiError( $this->handleApiError(
'Price mismatch detected - payload incomplete', 'Price mismatch detected - payload incomplete',
[ [
'apiTotal' => $apiTotal, 'apiTotal' => $apiTotal,
@@ -149,9 +149,9 @@ class Step3Controller extends AbstractController
'diagnostics' => $diagnostics, 'diagnostics' => $diagnostics,
], ],
'Preisabweichung festgestellt. Bitte wende dich an den Kundenservice.', 'Preisabweichung festgestellt. Bitte wende dich an den Kundenservice.',
$bookingCreateDto,
$form
); );
return $this->renderStepForm($bookingCreateDto, $form);
} }
// Validation successful - proceed to confirmation step // Validation successful - proceed to confirmation step
@@ -164,28 +164,26 @@ class Step3Controller extends AbstractController
return $this->redirectToRoute('app_booking_create_step_4'); return $this->redirectToRoute('app_booking_create_step_4');
} catch (TimeoutException $e) { } catch (TimeoutException $e) {
return $this->handleApiError( $this->handleApiError(
'Booking inquiry timeout', 'Booking inquiry timeout',
[ [
'exception' => $e->getMessage(), 'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(), 'trace' => $e->getTraceAsString(),
], ],
'Die Anfrage hat zu lange gedauert. Bitte versuche es erneut oder wende dich an den Kundenservice.', 'Die Anfrage hat zu lange gedauert. Bitte versuche es erneut oder wende dich an den Kundenservice.',
$bookingCreateDto,
$form
); );
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->handleApiError( $this->handleApiError(
'Booking inquiry exception', 'Booking inquiry exception',
[ [
'exception' => $e->getMessage(), 'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(), 'trace' => $e->getTraceAsString(),
], ],
'Ein allgemeiner Fehler ist aufgetreten. Bitte wende dich an den Kundenservice.', 'Ein allgemeiner Fehler ist aufgetreten. Bitte wende dich an den Kundenservice.',
$bookingCreateDto,
$form
); );
} }
return $this->renderStepForm($bookingCreateDto, $form);
} }
return $this->renderStepForm($bookingCreateDto, $form); return $this->renderStepForm($bookingCreateDto, $form);
@@ -92,13 +92,13 @@ class Step4Controller extends AbstractController
$bookingResponse = $this->apiClient->createBooking($bookingCreateDto); $bookingResponse = $this->apiClient->createBooking($bookingCreateDto);
if ($bookingResponse instanceof Notification) { if ($bookingResponse instanceof Notification) {
return $this->handleApiError( $this->handleApiError(
'Booking creation failed - API notification', 'Booking creation failed - API notification',
['message' => $bookingResponse->message], ['message' => $bookingResponse->message],
$bookingResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuchen es erneut.', $bookingResponse->message ?? 'Ein Fehler ist aufgetreten. Bitte versuchen es erneut.',
$bookingCreateDto,
$form
); );
return $this->renderStepForm($bookingCreateDto, $form, $newsletterOptInVisible, $newsletterTargetEmail);
} }
if (false === $bookingResponse->isBookingSuccessful()) { if (false === $bookingResponse->isBookingSuccessful()) {
@@ -107,13 +107,13 @@ class Step4Controller extends AbstractController
$errorMessage .= ' '.$bookingResponse->message; $errorMessage .= ' '.$bookingResponse->message;
} }
return $this->handleApiError( $this->handleApiError(
'Booking creation unsuccessful', 'Booking creation unsuccessful',
['status' => $bookingResponse->status, 'message' => $bookingResponse->message], ['status' => $bookingResponse->status, 'message' => $bookingResponse->message],
$errorMessage, $errorMessage,
$bookingCreateDto,
$form
); );
return $this->renderStepForm($bookingCreateDto, $form, $newsletterOptInVisible, $newsletterTargetEmail);
} }
$newsletterOptInSelected = $newsletterOptInVisible $newsletterOptInSelected = $newsletterOptInVisible
@@ -147,26 +147,22 @@ class Step4Controller extends AbstractController
return $this->redirectToRoute('app_booking_create_success'); return $this->redirectToRoute('app_booking_create_success');
} catch (TimeoutException $e) { } catch (TimeoutException $e) {
return $this->handleApiError( $this->handleApiError(
'Booking creation timeout', 'Booking creation timeout',
[ [
'exception' => $e->getMessage(), 'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(), 'trace' => $e->getTraceAsString(),
], ],
'Die Anfrage hat zu lange gedauert. Bitte versuche es erneut.', 'Die Anfrage hat zu lange gedauert. Bitte versuche es erneut.',
$bookingCreateDto,
$form
); );
} catch (\Exception $e) { } catch (\Exception $e) {
return $this->handleApiError( $this->handleApiError(
'Booking creation exception', 'Booking creation exception',
[ [
'exception' => $e->getMessage(), 'exception' => $e->getMessage(),
'trace' => $e->getTraceAsString(), 'trace' => $e->getTraceAsString(),
], ],
'Ein technischer Fehler ist aufgetreten.', 'Ein technischer Fehler ist aufgetreten.',
$bookingCreateDto,
$form
); );
} }
} }
@@ -5,9 +5,7 @@ declare(strict_types=1);
namespace App\Controller\Booking\Traits; namespace App\Controller\Booking\Traits;
use App\Form\Model\BookingDto; use App\Form\Model\BookingDto;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
/** /**
* Provides common functionality for booking creation controllers. * Provides common functionality for booking creation controllers.
@@ -82,18 +80,14 @@ trait BookingCreateTrait
} }
/** /**
* Handles API errors by logging, adding flash message, and rendering the form. * Handles API errors by logging and adding a flash message.
*/ */
private function handleApiError( private function handleApiError(
string $logMessage, string $logMessage,
array $context, array $context,
string $flashMessage, string $flashMessage,
BookingDto $bookingCreateDto, ): void {
FormInterface $form,
): Response {
$this->logger->error($logMessage, $context); $this->logger->error($logMessage, $context);
$this->addFlash('error', $flashMessage); $this->addFlash('error', $flashMessage);
return $this->renderStepForm($bookingCreateDto, $form);
} }
} }