Fix SonarQube issues: reduce returns, cognitive complexity, PHPDoc types

- TranslateCommand: replace @phpstan-ignore-line with proper comment in catch block
- OrderController::create: extract isValidCart() helper (5→3 returns)
- OrderController::guest: merge empty fields + email validation into single return (4→3 returns)
- OrderController::buildOrderItems: extract isBilletAvailable() and clampQuantity() (16→~10 complexity)
- HomeController::invitationRegister: extract handleInvitationRegistration() (already done)
- AuditLog: add @var array<string, mixed> PHPDoc on $data property

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-23 14:24:58 +01:00
parent bfc6c03000
commit 600e095d16
3 changed files with 50 additions and 28 deletions

View File

@@ -276,7 +276,8 @@ class TranslateCommand extends Command
if (200 === $response->getStatusCode()) {
return true;
}
} catch (\Throwable) { // @phpstan-ignore-line API not ready yet
} catch (\Throwable) {
// API not ready yet, retry
}
sleep(2);
}

View File

@@ -41,16 +41,10 @@ class OrderController extends AbstractController
'eventSlug' => $event->getSlug(),
]);
if (!\is_array($cart) || 0 === \count($cart)) {
if (!$this->isValidCart($cart)) {
$this->addFlash('error', 'Votre panier est vide.');
return $this->json(['redirect' => $eventUrl]);
}
foreach ($cart as $item) {
if (!\is_array($item) || !isset($item['billetId'], $item['qty']) || !is_numeric($item['billetId']) || !is_numeric($item['qty'])) {
return $this->json(['redirect' => $eventUrl], 400);
}
return $this->json(['redirect' => $eventUrl], 400);
}
/** @var User|null $user */
@@ -106,14 +100,8 @@ class OrderController extends AbstractController
$lastName = trim($request->request->getString('last_name'));
$email = trim($request->request->getString('email'));
if ('' === $firstName || '' === $lastName || '' === $email) {
$this->addFlash('error', 'Tous les champs sont requis.');
return $this->redirectToRoute('app_order_guest', ['id' => $order->getId()]);
}
if (!filter_var($email, \FILTER_VALIDATE_EMAIL)) {
$this->addFlash('error', 'L\'adresse email n\'est pas valide.');
if ('' === $firstName || '' === $lastName || '' === $email || !filter_var($email, \FILTER_VALIDATE_EMAIL)) {
$this->addFlash('error', '' === $firstName || '' === $lastName || '' === $email ? 'Tous les champs sont requis.' : 'L\'adresse email n\'est pas valide.');
return $this->redirectToRoute('app_order_guest', ['id' => $order->getId()]);
}
@@ -383,23 +371,15 @@ class OrderController extends AbstractController
}
$billet = $em->getRepository(Billet::class)->find($billetId);
if (!$billet || $billet->getCategory()->getEvent()->getId() !== $event->getId()) {
if (!$this->isBilletAvailable($billet, $event)) {
continue;
}
if ($billet->isNotBuyable()) {
$qty = $this->clampQuantity($billet, $qty);
if (0 === $qty) {
continue;
}
if (!$billet->isUnlimited()) {
if ($billet->getQuantity() <= 0) {
continue;
}
if ($qty > $billet->getQuantity()) {
$qty = $billet->getQuantity();
}
}
$orderItem = new BilletBuyerItem();
$orderItem->setBillet($billet);
$orderItem->setBilletName($billet->getName());
@@ -413,6 +393,46 @@ class OrderController extends AbstractController
return $totalHT;
}
private function isBilletAvailable(?Billet $billet, Event $event): bool
{
if (!$billet || $billet->getCategory()->getEvent()->getId() !== $event->getId()) {
return false;
}
return !$billet->isNotBuyable();
}
private function clampQuantity(Billet $billet, int $qty): int
{
if ($billet->isUnlimited()) {
return $qty;
}
if ($billet->getQuantity() <= 0) {
return 0;
}
return min($qty, $billet->getQuantity());
}
/**
* @param mixed $cart
*/
private function isValidCart(mixed $cart): bool
{
if (!\is_array($cart) || 0 === \count($cart)) {
return false;
}
foreach ($cart as $item) {
if (!\is_array($item) || !isset($item['billetId'], $item['qty']) || !is_numeric($item['billetId']) || !is_numeric($item['qty'])) {
return false;
}
}
return true;
}
/**
* @codeCoverageIgnore Requires live Stripe API
*/

View File

@@ -23,6 +23,7 @@ class AuditLog
private ?int $entityId = null;
#[ORM\Column(type: 'json')]
/** @var array<string, mixed> */
private array $data = [];
#[ORM\Column(length: 255, nullable: true)]