Lines
100.00%
12 / 12
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Index | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 3 | 100.00% | 1 / 1 | |||
| __invoke | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Controller\AgentStat; | |
| 6 | ||
| 7 | use App\ApiResource\Bannergress; | |
| 8 | use App\Controller\BaseController; | |
| 9 | use App\Entity\AgentStat; | |
| 10 | use App\Enum\UserRole; | |
| 11 | use App\Medal\MedalChecker; | |
| 12 | use App\Repository\AgentStatRepository; | |
| 13 | use App\Repository\DoneBannerRepository; | |
| 14 | use App\Repository\TimelineEventRepository; | |
| 15 | use App\Timeline\TimelineBuilder; | |
| 16 | use App\Timeline\TimelineEntry; | |
| 17 | use Symfony\Component\HttpFoundation\Response; | |
| 18 | use Symfony\Component\Routing\Attribute\Route; | |
| 19 | use Symfony\Component\Security\Http\Attribute\IsGranted; | |
| 20 | ||
| 21 | /** | |
| 22 | * The user's latest stats with medals and custom medals, as in the app, what the app synced from | |
| 23 | * Bannergress and the number of timeline entries of each kind, linking to the timeline (Timeline). | |
| 24 | */ | |
| 25 | #[Route('/agent-stats', name: 'app_agent_stat_index', methods: ['GET'])] | |
| 26 | #[IsGranted(UserRole::USER->value)] | |
| 27 | final class Index extends BaseController | |
| 28 | { | |
| 29 | public function __invoke( | |
| 30 | AgentStatRepository $agentStatRepository, | |
| 31 | TimelineEventRepository $timelineEventRepository, | |
| 32 | MedalChecker $medalChecker, | |
| 33 | TimelineBuilder $timelineBuilder, | |
| 34 | DoneBannerRepository $doneBannerRepository, | |
| 35 | ): Response { | |
| 36 | $agentStats = $agentStatRepository->findByOwner($this->getUser()); | |
| 37 | $events = $timelineEventRepository->findByOwner($this->getUser()); | |
| 38 | $latest = $agentStats[0] ?? null; | |
| 39 | ||
| 40 | return $this->render('agent_stat/index.html.twig', [ | |
| 41 | 'latest' => $latest, | |
| 42 | 'first' => \array_last($agentStats), | |
| 43 | 'medals' => $latest instanceof AgentStat ? $medalChecker->medalLevels($latest) : [], | |
| 44 | 'coreBadges' => $latest instanceof AgentStat ? $medalChecker->coreBadges($latest->getStats()['months_subscribed'] ?? 0) : [], | |
| 45 | 'customMedals' => $medalChecker->customMedalTiers($this->getUser()->getCustomMedals()), | |
| 46 | 'timelineCounts' => TimelineEntry::counts($timelineBuilder->build($agentStats, $events, $doneBannerRepository->findDatedByOwner($this->getUser()))), | |
| 47 | 'bannergress' => Bannergress::fromStored($this->getUser()->getBannergress()), | |
| 48 | ]); | |
| 49 | } | |
| 50 | } |