diff --git a/src/Infrastructure/Persistence/Doctrine/Report/DoctrineReportCommentRepository.php b/src/Infrastructure/Persistence/Doctrine/Report/Repository/DoctrineReportCommentRepository.php similarity index 88% rename from src/Infrastructure/Persistence/Doctrine/Report/DoctrineReportCommentRepository.php rename to src/Infrastructure/Persistence/Doctrine/Report/Repository/DoctrineReportCommentRepository.php index 98b5a84..c796101 100644 --- a/src/Infrastructure/Persistence/Doctrine/Report/DoctrineReportCommentRepository.php +++ b/src/Infrastructure/Persistence/Doctrine/Report/Repository/DoctrineReportCommentRepository.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Infrastructure\Persistence\Doctrine\Report; +namespace App\Infrastructure\Persistence\Doctrine\Report\Repository; use App\Domain\Model\Report\ReportComment; use App\Domain\Repository\Report\ReportCommentRepositoryInterface; diff --git a/src/Infrastructure/Persistence/Doctrine/Report/DoctrineReportRepository.php b/src/Infrastructure/Persistence/Doctrine/Report/Repository/DoctrineReportRepository.php similarity index 95% rename from src/Infrastructure/Persistence/Doctrine/Report/DoctrineReportRepository.php rename to src/Infrastructure/Persistence/Doctrine/Report/Repository/DoctrineReportRepository.php index a871a08..0dbc7b9 100644 --- a/src/Infrastructure/Persistence/Doctrine/Report/DoctrineReportRepository.php +++ b/src/Infrastructure/Persistence/Doctrine/Report/Repository/DoctrineReportRepository.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Infrastructure\Persistence\Doctrine\Report; +namespace App\Infrastructure\Persistence\Doctrine\Report\Repository; use App\Domain\Model\Report\Report; use App\Domain\Repository\Report\ReportRepositoryInterface; diff --git a/src/Presentation/Controller/ReportsController.php b/src/Presentation/Controller/ReportsController.php index 3ffca88..d847ea7 100644 --- a/src/Presentation/Controller/ReportsController.php +++ b/src/Presentation/Controller/ReportsController.php @@ -21,13 +21,21 @@ #[Route(path: '/reports')] class ReportsController extends AbstractController { - #[Route(path: '/{gameSlug}', name: 'reports_for_game', methods: [Request::METHOD_GET])] + #[ + Route( + path: '/{gameSlug}', + name: 'reports_for_game', + methods: [Request::METHOD_GET], + ), + ] public function reportsForGame( string $gameSlug, MessageBusInterface $messageBus, MessageBusHelper $messageBusHelper, ): Response { - $gameEnvelope = $messageBus->dispatch(new GetGameBySlugQuery($gameSlug)); + $gameEnvelope = $messageBus->dispatch( + new GetGameBySlugQuery($gameSlug), + ); /** @var ?Game $game */ $game = $messageBusHelper->getContentFromEnvelope( @@ -38,9 +46,13 @@ class: Game::class, if (null === $game) { try { - $messageBus->dispatch(new CreateGameWithCacheCheckCommand($gameSlug)); + $messageBus->dispatch( + new CreateGameWithCacheCheckCommand($gameSlug), + ); - $gameEnvelope = $messageBus->dispatch(new GetGameBySlugQuery($gameSlug)); + $gameEnvelope = $messageBus->dispatch( + new GetGameBySlugQuery($gameSlug), + ); /** @var ?Game $game */ $game = $messageBusHelper->getContentFromEnvelope( @@ -53,21 +65,19 @@ class: Game::class, '@app/reports/reports_for_game.html.twig', [ 'error' => $e->getMessage(), - ] + ], ); } } if (null === $game) { - return $this->render( - '@app/reports/reports_for_game.html.twig', - [ - 'error' => 'Game retrieval failed', - ] - ); + return $this->render('@app/reports/reports_for_game.html.twig', [ + 'error' => 'Game retrieval failed', + ]); } $reports = $game->getReports()->toArray(); + $mostUpvotedReport = null; if (!empty($reports)) { /** @var array $reports */ @@ -78,31 +88,27 @@ class: Game::class, return $b->getCreatedAt() <=> $a->getCreatedAt(); }); + + $mostUpvotedReport = $reports[0]; } - $createReportForm = $this->createForm( - CreateReportForm::class, - null, - [ - 'action' => $this->generateUrl('create_report'), - 'method' => Request::METHOD_POST, - ] - ); + $createReportForm = $this->createForm(CreateReportForm::class, null, [ + 'action' => $this->generateUrl('create_report'), + 'method' => Request::METHOD_POST, + ]); $createReportCommentForm = $this->createForm( CreateReportCommentForm::class, null, ); - return $this->render( - '@app/reports/reports_for_game.html.twig', - [ - 'game' => $game, - 'reports' => $reports ?? [], - 'gameSlug' => $game->getSlug(), - 'createReportForm' => $createReportForm->createView(), - 'createReportCommentForm' => $createReportCommentForm->createView(), - ] - ); + return $this->render('@app/reports/reports_for_game.html.twig', [ + 'game' => $game, + 'reports' => $reports ?? [], + 'gameSlug' => $game->getSlug(), + 'mostUpvotedReport' => $mostUpvotedReport, + 'createReportForm' => $createReportForm->createView(), + 'createReportCommentForm' => $createReportCommentForm->createView(), + ]); } } diff --git a/tests/Unit/Application/CommandHandler/Report/CreateReportCommentCommandHandlerTest.php b/tests/Unit/Application/CommandHandler/Report/CreateReportCommentCommandHandlerTest.php index c997f20..0341453 100644 --- a/tests/Unit/Application/CommandHandler/Report/CreateReportCommentCommandHandlerTest.php +++ b/tests/Unit/Application/CommandHandler/Report/CreateReportCommentCommandHandlerTest.php @@ -11,7 +11,7 @@ use App\Application\Query\Report\GetReportByIdQuery; use App\Domain\Model\Report\Report; use App\Domain\Model\Report\ReportComment; -use App\Infrastructure\Persistence\Doctrine\Report\DoctrineReportCommentRepository; +use App\Infrastructure\Persistence\Doctrine\Report\Repository\DoctrineReportCommentRepository; use Faker\Factory; use Psr\Log\LoggerInterface; use Symfony\Component\Messenger\Envelope; diff --git a/tests/Unit/Application/CommandHandler/Report/CreateReportFromDtoCommandHandlerTest.php b/tests/Unit/Application/CommandHandler/Report/CreateReportFromDtoCommandHandlerTest.php index 346d308..f7fe605 100644 --- a/tests/Unit/Application/CommandHandler/Report/CreateReportFromDtoCommandHandlerTest.php +++ b/tests/Unit/Application/CommandHandler/Report/CreateReportFromDtoCommandHandlerTest.php @@ -10,7 +10,7 @@ use App\Domain\Model\Report\Report; use App\Infrastructure\Enum\ReportGameStatusEnum; use App\Infrastructure\Persistence\Doctrine\Game\Repository\DoctrineGameRepository; -use App\Infrastructure\Persistence\Doctrine\Report\DoctrineReportRepository; +use App\Infrastructure\Persistence\Doctrine\Report\Repository\DoctrineReportRepository; use App\Presentation\Dto\CreateReportFormInputDto; use Faker\Factory;