fix: SonarQube - DashboardController, DevisController, WebhookStripeController
DashboardController : - CLIENT_URL_PREFIX constante (7 occurrences) DevisController : - MSG_NOT_FOUND constante (7 occurrences) - handleSave CC 20->~12 : extraction createDevisLine() - send : fusion 2 guards (4->3 returns) - resend : fusion 2 guards (4->3 returns) WebhookStripeController : - LOG_PI_SUCCEEDED constante (4 occurrences) - handlePaymentSucceeded : extraction checkPaymentPreConditions (4->2 returns) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
#[IsGranted('ROLE_EMPLOYE')]
|
||||
class DashboardController extends AbstractController
|
||||
{
|
||||
private const CLIENT_URL_PREFIX = '/admin/clients/';
|
||||
|
||||
#[Route('', name: 'dashboard')]
|
||||
public function index(): Response
|
||||
{
|
||||
@@ -36,19 +38,19 @@ class DashboardController extends AbstractController
|
||||
$results = [];
|
||||
|
||||
foreach ($meilisearch->searchCustomers($q, 5) as $h) {
|
||||
$results[] = ['type' => 'client', 'label' => $h['fullName'] ?? $h['raisonSociale'] ?? '', 'sub' => $h['email'] ?? '', 'url' => '/admin/clients/'.$h['id']];
|
||||
$results[] = ['type' => 'client', 'label' => $h['fullName'] ?? $h['raisonSociale'] ?? '', 'sub' => $h['email'] ?? '', 'url' => self::CLIENT_URL_PREFIX.$h['id']];
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchDomains($q, 5) as $h) {
|
||||
$results[] = ['type' => 'ndd', 'label' => $h['fqdn'] ?? '', 'sub' => $h['customerName'] ?? '', 'url' => '/admin/clients/'.($h['customerId'] ?? 0).'?tab=ndd'];
|
||||
$results[] = ['type' => 'ndd', 'label' => $h['fqdn'] ?? '', 'sub' => $h['customerName'] ?? '', 'url' => self::CLIENT_URL_PREFIX.($h['customerId'] ?? 0).'?tab=ndd'];
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchWebsites($q, 5) as $h) {
|
||||
$results[] = ['type' => 'site', 'label' => $h['name'] ?? '', 'sub' => $h['customerName'] ?? '', 'url' => '/admin/clients/'.($h['customerId'] ?? 0).'?tab=sites'];
|
||||
$results[] = ['type' => 'site', 'label' => $h['name'] ?? '', 'sub' => $h['customerName'] ?? '', 'url' => self::CLIENT_URL_PREFIX.($h['customerId'] ?? 0).'?tab=sites'];
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchContacts($q, 5) as $h) {
|
||||
$results[] = ['type' => 'contact', 'label' => $h['fullName'] ?? '', 'sub' => ($h['role'] ?? '').($h['email'] ? ' — '.$h['email'] : ''), 'url' => '/admin/clients/'.($h['customerId'] ?? 0).'?tab=contacts'];
|
||||
$results[] = ['type' => 'contact', 'label' => $h['fullName'] ?? '', 'sub' => ($h['role'] ?? '').($h['email'] ? ' — '.$h['email'] : ''), 'url' => self::CLIENT_URL_PREFIX.($h['customerId'] ?? 0).'?tab=contacts'];
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchRevendeurs($q, 3) as $h) {
|
||||
@@ -56,15 +58,15 @@ class DashboardController extends AbstractController
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchDevis($q, 3) as $h) {
|
||||
$results[] = ['type' => 'devis', 'label' => $h['numOrder'] ?? '', 'sub' => ($h['customerName'] ?? '').' — '.($h['totalTtc'] ?? '0').' EUR', 'url' => '/admin/clients/'.($h['customerId'] ?? 0).'?tab=devis'];
|
||||
$results[] = ['type' => 'devis', 'label' => $h['numOrder'] ?? '', 'sub' => ($h['customerName'] ?? '').' — '.($h['totalTtc'] ?? '0').' EUR', 'url' => self::CLIENT_URL_PREFIX.($h['customerId'] ?? 0).'?tab=devis'];
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchAdverts($q, 3) as $h) {
|
||||
$results[] = ['type' => 'avis', 'label' => $h['numOrder'] ?? '', 'sub' => ($h['customerName'] ?? '').' — '.($h['totalTtc'] ?? '0').' EUR', 'url' => '/admin/clients/'.($h['customerId'] ?? 0).'?tab=avis'];
|
||||
$results[] = ['type' => 'avis', 'label' => $h['numOrder'] ?? '', 'sub' => ($h['customerName'] ?? '').' — '.($h['totalTtc'] ?? '0').' EUR', 'url' => self::CLIENT_URL_PREFIX.($h['customerId'] ?? 0).'?tab=avis'];
|
||||
}
|
||||
|
||||
foreach ($meilisearch->searchFactures($q, 3) as $h) {
|
||||
$results[] = ['type' => 'facture', 'label' => $h['invoiceNumber'] ?? '', 'sub' => ($h['customerName'] ?? '').' — '.($h['totalTtc'] ?? '0').' EUR', 'url' => '/admin/clients/'.($h['customerId'] ?? 0).'?tab=factures'];
|
||||
$results[] = ['type' => 'facture', 'label' => $h['invoiceNumber'] ?? '', 'sub' => ($h['customerName'] ?? '').' — '.($h['totalTtc'] ?? '0').' EUR', 'url' => self::CLIENT_URL_PREFIX.($h['customerId'] ?? 0).'?tab=factures'];
|
||||
}
|
||||
|
||||
return new JsonResponse($results);
|
||||
|
||||
@@ -30,6 +30,8 @@ use Twig\Environment;
|
||||
#[IsGranted('ROLE_EMPLOYE')]
|
||||
class DevisController extends AbstractController
|
||||
{
|
||||
private const MSG_NOT_FOUND = 'Devis introuvable';
|
||||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private OrderNumberService $orderNumberService,
|
||||
@@ -113,7 +115,7 @@ class DevisController extends AbstractController
|
||||
{
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (Devis::STATE_CANCEL === $devis->getState()) {
|
||||
@@ -186,21 +188,7 @@ class DevisController extends AbstractController
|
||||
}
|
||||
|
||||
$priceHt = (float) str_replace(',', '.', (string) ($data['priceHt'] ?? '0'));
|
||||
|
||||
$line = new DevisLine($devis, $title, number_format($priceHt, 2, '.', ''), $pos);
|
||||
$description = trim((string) ($data['description'] ?? ''));
|
||||
if ('' !== $description) {
|
||||
$line->setDescription($description);
|
||||
}
|
||||
$lineType = trim((string) ($data['type'] ?? ''));
|
||||
if ('' !== $lineType) {
|
||||
$line->setType($lineType);
|
||||
}
|
||||
$lineServiceId = (int) ($data['serviceId'] ?? 0);
|
||||
if ($lineServiceId > 0) {
|
||||
$line->setServiceId($lineServiceId);
|
||||
}
|
||||
|
||||
$line = $this->createDevisLine($devis, $data, $title, $priceHt, $pos);
|
||||
$this->em->persist($line);
|
||||
$devis->addLine($line);
|
||||
|
||||
@@ -235,11 +223,33 @@ class DevisController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/{id}/generate-pdf', name: 'generate_pdf', requirements: ['id' => '\d+'], methods: ['POST'])]
|
||||
/**
|
||||
* @param array{title?: string, description?: string, priceHt?: string, pos?: string|int, type?: string, serviceId?: string|int} $data
|
||||
*/
|
||||
private function createDevisLine(Devis $devis, array $data, string $title, float $priceHt, int $pos): DevisLine
|
||||
{
|
||||
$line = new DevisLine($devis, $title, number_format($priceHt, 2, '.', ''), $pos);
|
||||
$description = trim((string) ($data['description'] ?? ''));
|
||||
if ('' !== $description) {
|
||||
$line->setDescription($description);
|
||||
}
|
||||
$lineType = trim((string) ($data['type'] ?? ''));
|
||||
if ('' !== $lineType) {
|
||||
$line->setType($lineType);
|
||||
}
|
||||
$lineServiceId = (int) ($data['serviceId'] ?? 0);
|
||||
if ($lineServiceId > 0) {
|
||||
$line->setServiceId($lineServiceId);
|
||||
}
|
||||
|
||||
return $line;
|
||||
}
|
||||
|
||||
public function generatePdf(int $id, KernelInterface $kernel, Environment $twig): Response
|
||||
{
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
// Generation du PDF (devis + CGV fusionnees via FPDI)
|
||||
@@ -290,7 +300,7 @@ class DevisController extends AbstractController
|
||||
{
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
$submitterId = (int) ($devis->getSubmissionId() ?? '0');
|
||||
@@ -323,24 +333,15 @@ class DevisController extends AbstractController
|
||||
): Response {
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
}
|
||||
|
||||
if (null === $devis->getUnsignedPdf()) {
|
||||
$this->addFlash('error', 'Le PDF du devis doit etre genere avant l\'envoi.');
|
||||
|
||||
return $this->redirectToRoute('app_admin_clients_show', [
|
||||
'id' => $devis->getCustomer()?->getId() ?? 0,
|
||||
'tab' => 'devis',
|
||||
]);
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
$customer = $devis->getCustomer();
|
||||
if (null === $customer || null === $customer->getEmail()) {
|
||||
$this->addFlash('error', 'Client ou email introuvable.');
|
||||
if (null === $devis->getUnsignedPdf() || null === $customer || null === $customer->getEmail()) {
|
||||
$this->addFlash('error', null === $devis->getUnsignedPdf() ? 'Le PDF du devis doit etre genere avant l\'envoi.' : 'Client ou email introuvable.');
|
||||
|
||||
return $this->redirectToRoute('app_admin_clients_show', [
|
||||
'id' => $customer?->getId() ?? 0,
|
||||
'id' => $customer?->getId() ?? ($devis->getCustomer()?->getId() ?? 0),
|
||||
'tab' => 'devis',
|
||||
]);
|
||||
}
|
||||
@@ -404,12 +405,12 @@ class DevisController extends AbstractController
|
||||
): Response {
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
$customer = $devis->getCustomer();
|
||||
if (null === $customer || null === $customer->getEmail()) {
|
||||
$this->addFlash('error', 'Client ou email introuvable.');
|
||||
if (null === $customer || null === $customer->getEmail() || null === $devis->getUnsignedPdf()) {
|
||||
$this->addFlash('error', null === $devis->getUnsignedPdf() ? 'Le PDF doit exister pour renvoyer le lien.' : 'Client ou email introuvable.');
|
||||
|
||||
return $this->redirectToRoute('app_admin_clients_show', [
|
||||
'id' => $customer?->getId() ?? 0,
|
||||
@@ -417,15 +418,6 @@ class DevisController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
if (null === $devis->getUnsignedPdf()) {
|
||||
$this->addFlash('error', 'Le PDF doit exister pour renvoyer le lien.');
|
||||
|
||||
return $this->redirectToRoute('app_admin_clients_show', [
|
||||
'id' => $customer->getId(),
|
||||
'tab' => 'devis',
|
||||
]);
|
||||
}
|
||||
|
||||
$signedRedirectUrl = $urlGenerator->generate('app_devis_process_signed', [
|
||||
'id' => $devis->getId(),
|
||||
'hmac' => $devis->getHmac(),
|
||||
@@ -477,7 +469,7 @@ class DevisController extends AbstractController
|
||||
{
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (Devis::STATE_ACCEPTED !== $devis->getState()) {
|
||||
@@ -548,7 +540,7 @@ class DevisController extends AbstractController
|
||||
{
|
||||
$devis = $this->em->getRepository(Devis::class)->find($id);
|
||||
if (null === $devis) {
|
||||
throw $this->createNotFoundException('Devis introuvable');
|
||||
throw $this->createNotFoundException(self::MSG_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (Devis::STATE_CANCEL === $devis->getState()) {
|
||||
|
||||
Reference in New Issue
Block a user