Lines 100.00% 1 / 1
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
Agent 100.00% 1 / 1 100.00% 1 / 1 1 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace App\ApiResource;
6
7use ApiPlatform\Metadata\ApiProperty;
8use ApiPlatform\Metadata\ApiResource;
9use ApiPlatform\Metadata\Get;
10use ApiPlatform\Metadata\GetCollection;
11use App\State\AgentProvider;
12use Symfony\Component\Serializer\Attribute\Groups;
13
14/**
15 * Other agents' profiles for the app, as web's /agents and /agents/{agentName}: only agents who
16 * show the agent part, and only the parts they show (null for the others).
17 */
18#[ApiResource(
19    description: 'Agents who show their profile to other users (the agent part, see Me::visibleParts), and the parts they show; private parts are null. The list has the agent name, faction, level and avatar; an agent also has latestStats (a stats row with the column names of /api/agent-stats), history (all stats rows, newest first) with events (the custom timeline events: date, endDate (null for one day) and text, newest first), customMedals, bannergress (as Me has it) and doneBanners (as /api/done-banners has them, without the id).',
20    operations: [
21        new GetCollection(
22            uriTemplate: '/agents',
23            paginationEnabled: false,
24            normalizationContext: ['groups' => [self::READ]],
25            security: "is_granted('ROLE_USER')",
26            provider: AgentProvider::class,
27        ),
28        new Get(
29            uriTemplate: '/agents/{agentName}',
30            requirements: ['agentName' => '[A-Za-z0-9_]{1,50}'],
31            normalizationContext: ['groups' => [self::READ, self::ITEM]],
32            security: "is_granted('ROLE_USER')",
33            provider: AgentProvider::class,
34        ),
35    ],
36)]
37final readonly class Agent
38{
39    public const string READ = 'agent:read';
40
41    public const string ITEM = 'agent:item';
42
43    /**
44     * @param array<string, int|string|null>|null                                                                                                                                $latestStats with the latest stats part
45     * @param list<array<string, int|string|null>>|null                                                                                                                          $history     with the stats history part, newest first
46     * @param list<array{date: string, endDate: string|null, text: string}>|null                                                                                                 $events      the custom timeline events, with the stats history part, newest first
47     * @param list<array{bannerId: string, title: string, missions: int, picture: string|null, startLatitude: float|null, startLongitude: float|null, doneAt: string|null}>|null $doneBanners newest on the list first
48     */
49    public function __construct(
50        #[ApiProperty(identifier: true)]
51        #[Groups([self::READ])]
52        public string $agentName,
53        /** From the latest stats; null without stats. */
54        #[Groups([self::READ])]
55        public ?string $faction = null,
56        #[Groups([self::READ])]
57        public ?int $level = null,
58        /** The Google profile picture (data: URI), with the avatar part. */
59        #[Groups([self::READ])]
60        public ?string $avatar = null,
61        #[Groups([self::ITEM])]
62        public ?array $latestStats = null,
63        #[Groups([self::ITEM])]
64        public ?array $history = null,
65        #[Groups([self::ITEM])]
66        public ?array $events = null,
67        /** With the custom medals part. */
68        #[Groups([self::ITEM])]
69        public ?CustomMedals $customMedals = null,
70        /** With the Bannergress part, once the agent synced it. */
71        #[Groups([self::ITEM])]
72        public ?Bannergress $bannergress = null,
73        /** The done list with the days, with the Bannergress part. */
74        #[Groups([self::ITEM])]
75        public ?array $doneBanners = null,
76    ) {
77    }
78}