Lines 100.00% 11 / 11
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Read 100.00% 11 / 11 100.00% 1 / 1 4 100.00% 1 / 1
 __invoke 100.00% 11 / 11 100.00% 1 / 1 4
1<?php
2
3declare(strict_types=1);
4
5namespace App\Controller\Banners;
6
7use App\ApiResource\Bannergress;
8use App\Bannergress\BannerMap;
9use App\Controller\BaseController;
10use App\Entity\User;
11use App\Enum\ProfilePart;
12use App\Enum\UserRole;
13use App\Repository\DoneBannerRepository;
14use App\Repository\UserRepository;
15use Symfony\Component\HttpFoundation\Response;
16use Symfony\Component\Routing\Attribute\Route;
17use Symfony\Component\Security\Http\Attribute\IsGranted;
18
19/**
20 * An agent's Bannergress page, read-only; 404 without the agent and Bannergress parts or a sync.
21 */
22#[Route('/agents/{agentName}/banners', name: 'app_agent_banners', requirements: ['agentName' => '[A-Za-z0-9_]{1,50}'], methods: ['GET'])]
23#[IsGranted(UserRole::USER->value)]
24final class Read extends BaseController
25{
26    public function __invoke(string $agentName, UserRepository $userRepository, DoneBannerRepository $doneBannerRepository, BannerMap $bannerMap): Response
27    {
28        $agent = $userRepository->findOneByAgentName($agentName);
29        $bannergress = $agent instanceof User && $agent->isVisible(ProfilePart::BANNERGRESS) ? Bannergress::fromStored($agent->getBannergress()) : null;
30        if (!$bannergress instanceof Bannergress) {
31            throw $this->createNotFoundException('No Bannergress of '.$agentName.' to show.');
32        }
33
34        $doneBanners = $doneBannerRepository->findByOwner($agent);
35
36        return $this->render('banners/index.html.twig', [
37            'bannergress' => $bannergress,
38            'doneBanners' => $doneBanners,
39            'mapPoints' => $bannerMap->points($bannergress, $doneBanners),
40            'agent' => $agent,
41        ]);
42    }
43}