Reduce cognitive complexity: extract syncBilletToStripe, remove temp variable, fill empty catch blocks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -549,16 +549,7 @@ class AccountController extends AbstractController
|
||||
$this->hydrateBilletFromRequest($billet, $request);
|
||||
|
||||
$em->persist($billet);
|
||||
|
||||
if ($user->getStripeAccountId()) {
|
||||
try {
|
||||
$productId = $stripeService->createProduct($billet, $user->getStripeAccountId());
|
||||
$billet->setStripeProductId($productId);
|
||||
} catch (\Exception) {
|
||||
// Stripe failure is non-blocking
|
||||
}
|
||||
}
|
||||
|
||||
$this->syncBilletToStripe($billet, $user, $stripeService);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Billet ajoute avec succes.');
|
||||
@@ -596,20 +587,7 @@ class AccountController extends AbstractController
|
||||
|
||||
if ($request->isMethod('POST')) {
|
||||
$this->hydrateBilletFromRequest($billet, $request);
|
||||
|
||||
if ($user->getStripeAccountId()) {
|
||||
try {
|
||||
if ($billet->getStripeProductId()) {
|
||||
$stripeService->updateProduct($billet, $user->getStripeAccountId());
|
||||
} else {
|
||||
$productId = $stripeService->createProduct($billet, $user->getStripeAccountId());
|
||||
$billet->setStripeProductId($productId);
|
||||
}
|
||||
} catch (\Exception) {
|
||||
// Stripe failure is non-blocking
|
||||
}
|
||||
}
|
||||
|
||||
$this->syncBilletToStripe($billet, $user, $stripeService);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Billet modifie avec succes.');
|
||||
@@ -649,6 +627,7 @@ class AccountController extends AbstractController
|
||||
try {
|
||||
$stripeService->deleteProduct($billet->getStripeProductId(), $user->getStripeAccountId());
|
||||
} catch (\Exception) {
|
||||
// Stripe failure is non-blocking
|
||||
}
|
||||
}
|
||||
|
||||
@@ -696,7 +675,7 @@ class AccountController extends AbstractController
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$response = $this->render('account/billet_preview.html.twig', [
|
||||
return $this->render('account/billet_preview.html.twig', [
|
||||
'event' => $event,
|
||||
'user' => $user,
|
||||
'bg_color' => '#ffffff',
|
||||
@@ -707,8 +686,6 @@ class AccountController extends AbstractController
|
||||
'invitation_title' => $request->query->getString('invitation_title', 'Invitation'),
|
||||
'invitation_color' => $request->query->getString('invitation_color', '#d4a017'),
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
#[Route('/mon-compte/evenement/{id}/billet-design', name: 'app_account_event_save_billet_design', methods: ['POST'])]
|
||||
@@ -876,6 +853,24 @@ class AccountController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function syncBilletToStripe(Billet $billet, User $user, StripeService $stripeService): void
|
||||
{
|
||||
if (!$user->getStripeAccountId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if ($billet->getStripeProductId()) {
|
||||
$stripeService->updateProduct($billet, $user->getStripeAccountId());
|
||||
} else {
|
||||
$productId = $stripeService->createProduct($billet, $user->getStripeAccountId());
|
||||
$billet->setStripeProductId($productId);
|
||||
}
|
||||
} catch (\Exception) {
|
||||
// Stripe failure is non-blocking
|
||||
}
|
||||
}
|
||||
|
||||
private function hydrateEventFromRequest(Event $event, Request $request): void
|
||||
{
|
||||
$event->setTitle(trim($request->request->getString('title')));
|
||||
|
||||
Reference in New Issue
Block a user