Lines
100.00%
9 / 9
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AgentStatIndex | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| __invoke | 100.00% | 9 / 9 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Controller\Api; | |
| 6 | ||
| 7 | use App\Controller\BaseController; | |
| 8 | use App\Dto\AgentStatInput; | |
| 9 | use App\Entity\AgentStat; | |
| 10 | use App\Enum\UserRole; | |
| 11 | use App\Repository\AgentStatRepository; | |
| 12 | use Symfony\Component\HttpFoundation\JsonResponse; | |
| 13 | use Symfony\Component\Routing\Attribute\Route; | |
| 14 | use Symfony\Component\Security\Http\Attribute\IsGranted; | |
| 15 | ||
| 16 | /** | |
| 17 | * The user's agent stats, newest first, in the format of POST /api/agent-stats (plus the id). | |
| 18 | */ | |
| 19 | #[Route('/api/agent-stats', name: 'api_agent_stat_index', methods: ['GET'], format: 'json')] | |
| 20 | #[IsGranted(UserRole::USER->value)] | |
| 21 | final class AgentStatIndex extends BaseController | |
| 22 | { | |
| 23 | public function __invoke(AgentStatRepository $agentStatRepository): JsonResponse | |
| 24 | { | |
| 25 | return $this->json(\array_map( | |
| 26 | static fn (AgentStat $agentStat): array => [ | |
| 27 | 'id' => $agentStat->id, | |
| 28 | 'datetime' => $agentStat->datetime->format(AgentStatInput::DATETIME_FORMAT), | |
| 29 | 'nickname' => $agentStat->nickname, | |
| 30 | 'faction' => $agentStat->faction, | |
| 31 | ] + $agentStat->getStats(), | |
| 32 | $agentStatRepository->findByOwner($this->getUser()), | |
| 33 | )); | |
| 34 | } | |
| 35 | } |