From 0cf116085332a4ca7afba1e687b80049cc42358e Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Fri, 3 Apr 2026 09:35:26 +0200 Subject: [PATCH] Reduce AccountController to 20 methods, remove unused AdminOrdersController constant - Move export, exportPdf, payoutPdf from AccountController to AccountEventOperationsController (9 -> 12 methods) - Remove getAllowedBilletTypes delegate from AccountController - Update tests to reference AccountEventCatalogController for that method - Remove unused DQL_EXCLUDE_INVITATIONS from AdminOrdersController Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Controller/AccountController.php | 69 ------------------- .../AccountEventOperationsController.php | 63 +++++++++++++++++ src/Controller/AdminOrdersController.php | 1 - tests/Controller/AccountControllerTest.php | 8 +-- 4 files changed, 67 insertions(+), 74 deletions(-) diff --git a/src/Controller/AccountController.php b/src/Controller/AccountController.php index 69eeee7..b11d35f 100644 --- a/src/Controller/AccountController.php +++ b/src/Controller/AccountController.php @@ -13,10 +13,8 @@ use App\Entity\Payout; use App\Entity\User; use App\Service\AuditService; use App\Service\EventIndexService; -use App\Service\ExportService; use App\Service\MailerService; use App\Service\OrderIndexService; -use App\Service\PayoutPdfService; use App\Service\StripeService; use Doctrine\ORM\EntityManagerInterface; use Knp\Component\Pager\PaginatorInterface; @@ -595,73 +593,6 @@ class AccountController extends AbstractController } } - /** @codeCoverageIgnore Generates PDF with dompdf */ - #[Route('/mon-compte/payout/{id}/attestation', name: 'app_account_payout_pdf')] - public function payoutPdf(Payout $payout, PayoutPdfService $pdfService): Response - { - /** @var User $user */ - $user = $this->getUser(); - - if ($payout->getOrganizer()->getId() !== $user->getId()) { - throw $this->createAccessDeniedException(); - } - - return new Response($pdfService->generate($payout), 200, [ - 'Content-Type' => self::CONTENT_TYPE_PDF, - 'Content-Disposition' => 'inline; filename="attestation_'.$payout->getStripePayoutId().self::PDF_SUFFIX, - ]); - } - - #[Route('/mon-compte/export/{year}/{month}', name: 'app_account_export', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])] - public function export(int $year, int $month, ExportService $exportService): Response - { - $this->denyAccessUnlessGranted('ROLE_ORGANIZER'); - if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart - return $redirect; - } // @codeCoverageIgnoreEnd - - /** @var User $user */ - $user = $this->getUser(); - $stats = $exportService->getMonthlyStats($year, $month, $user); - $csv = $exportService->generateCsv($stats['orders']); - - $filename = sprintf('export_%04d_%02d.csv', $year, $month); - - return new Response($csv, 200, [ - 'Content-Type' => 'text/csv; charset=utf-8', - 'Content-Disposition' => 'attachment; filename="'.$filename.'"', - ]); - } - - #[Route('/mon-compte/export/{year}/{month}/pdf', name: 'app_account_export_pdf', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])] - public function exportPdf(int $year, int $month, ExportService $exportService): Response - { - $this->denyAccessUnlessGranted('ROLE_ORGANIZER'); - if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart - return $redirect; - } // @codeCoverageIgnoreEnd - - /** @var User $user */ - $user = $this->getUser(); - $stats = $exportService->getMonthlyStats($year, $month, $user); - $pdf = $exportService->generatePdf($stats, $year, $month, $user); - - $filename = sprintf('recap_%04d_%02d.pdf', $year, $month); - - return new Response($pdf, 200, [ - 'Content-Type' => self::CONTENT_TYPE_PDF, - 'Content-Disposition' => 'inline; filename="'.$filename.'"', - ]); - } - - /** - * @return string[] - */ - public static function getAllowedBilletTypes(?string $offer): array - { - return AccountEventCatalogController::getAllowedBilletTypes($offer); - } - /** * @param list $paidOrders * diff --git a/src/Controller/AccountEventOperationsController.php b/src/Controller/AccountEventOperationsController.php index 562ae14..1e69a1a 100644 --- a/src/Controller/AccountEventOperationsController.php +++ b/src/Controller/AccountEventOperationsController.php @@ -10,8 +10,12 @@ use App\Entity\BilletBuyerItem; use App\Entity\BilletOrder; use App\Entity\Category; use App\Entity\Event; +use App\Entity\Payout; +use App\Entity\User; use App\Service\AuditService; use App\Service\BilletOrderService; +use App\Service\ExportService; +use App\Service\PayoutPdfService; use App\Service\StripeService; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -549,4 +553,63 @@ class AccountEventOperationsController extends AbstractController return $details; } + + /** @codeCoverageIgnore Generates PDF with dompdf */ + #[Route('/mon-compte/payout/{id}/attestation', name: 'app_account_payout_pdf')] + public function payoutPdf(Payout $payout, PayoutPdfService $pdfService): Response + { + /** @var User $user */ + $user = $this->getUser(); + + if ($payout->getOrganizer()->getId() !== $user->getId()) { + throw $this->createAccessDeniedException(); + } + + return new Response($pdfService->generate($payout), 200, [ + 'Content-Type' => self::CONTENT_TYPE_PDF, + 'Content-Disposition' => 'inline; filename="attestation_'.$payout->getStripePayoutId().self::PDF_SUFFIX, + ]); + } + + #[Route('/mon-compte/export/{year}/{month}', name: 'app_account_export', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])] + public function export(int $year, int $month, ExportService $exportService): Response + { + $this->denyAccessUnlessGranted('ROLE_ORGANIZER'); + if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart + return $redirect; + } // @codeCoverageIgnoreEnd + + /** @var User $user */ + $user = $this->getUser(); + $stats = $exportService->getMonthlyStats($year, $month, $user); + $csv = $exportService->generateCsv($stats['orders']); + + $filename = sprintf('export_%04d_%02d.csv', $year, $month); + + return new Response($csv, 200, [ + 'Content-Type' => 'text/csv; charset=utf-8', + 'Content-Disposition' => 'attachment; filename="'.$filename.'"', + ]); + } + + #[Route('/mon-compte/export/{year}/{month}/pdf', name: 'app_account_export_pdf', requirements: ['year' => '\d{4}', 'month' => '\d{1,2}'], methods: ['GET'])] + public function exportPdf(int $year, int $month, ExportService $exportService): Response + { + $this->denyAccessUnlessGranted('ROLE_ORGANIZER'); + if ($redirect = $this->requireStripeReady()) { // @codeCoverageIgnoreStart + return $redirect; + } // @codeCoverageIgnoreEnd + + /** @var User $user */ + $user = $this->getUser(); + $stats = $exportService->getMonthlyStats($year, $month, $user); + $pdf = $exportService->generatePdf($stats, $year, $month, $user); + + $filename = sprintf('recap_%04d_%02d.pdf', $year, $month); + + return new Response($pdf, 200, [ + 'Content-Type' => self::CONTENT_TYPE_PDF, + 'Content-Disposition' => 'inline; filename="'.$filename.'"', + ]); + } } diff --git a/src/Controller/AdminOrdersController.php b/src/Controller/AdminOrdersController.php index e848f65..3544962 100644 --- a/src/Controller/AdminOrdersController.php +++ b/src/Controller/AdminOrdersController.php @@ -25,7 +25,6 @@ use Symfony\Component\Security\Http\Attribute\IsGranted; class AdminOrdersController extends AbstractController { private const DQL_STATUS_PAID = 'o.status = :paid'; - private const DQL_EXCLUDE_INVITATIONS = 'o.isInvitation = false OR o.isInvitation IS NULL'; #[Route('/commandes', name: 'app_admin_orders', methods: ['GET'])] public function orders(Request $request, EntityManagerInterface $em, PaginatorInterface $paginator): Response diff --git a/tests/Controller/AccountControllerTest.php b/tests/Controller/AccountControllerTest.php index 861cfff..a094a79 100644 --- a/tests/Controller/AccountControllerTest.php +++ b/tests/Controller/AccountControllerTest.php @@ -2049,25 +2049,25 @@ class AccountControllerTest extends WebTestCase public function testGetAllowedBilletTypesBasic(): void { - $types = \App\Controller\AccountController::getAllowedBilletTypes('basic'); + $types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes('basic'); self::assertSame(['billet', 'reservation_brocante', 'vote'], $types); } public function testGetAllowedBilletTypesSurMesure(): void { - $types = \App\Controller\AccountController::getAllowedBilletTypes('sur-mesure'); + $types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes('sur-mesure'); self::assertSame(['billet', 'reservation_brocante', 'vote'], $types); } public function testGetAllowedBilletTypesFree(): void { - $types = \App\Controller\AccountController::getAllowedBilletTypes('free'); + $types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes('free'); self::assertSame(['billet'], $types); } public function testGetAllowedBilletTypesNull(): void { - $types = \App\Controller\AccountController::getAllowedBilletTypes(null); + $types = \App\Controller\AccountEventCatalogController::getAllowedBilletTypes(null); self::assertSame(['billet'], $types); }