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 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Controller\Banners; | |
| 6 | ||
| 7 | use App\ApiResource\Bannergress; | |
| 8 | use App\Bannergress\BannerMap; | |
| 9 | use App\Controller\BaseController; | |
| 10 | use App\Entity\User; | |
| 11 | use App\Enum\ProfilePart; | |
| 12 | use App\Enum\UserRole; | |
| 13 | use App\Repository\DoneBannerRepository; | |
| 14 | use App\Repository\UserRepository; | |
| 15 | use Symfony\Component\HttpFoundation\Response; | |
| 16 | use Symfony\Component\Routing\Attribute\Route; | |
| 17 | use 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)] | |
| 24 | final 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 | } |