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
UserPrivacy 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\GetCollection;
10use App\State\UserPrivacyProvider;
11use Symfony\Component\Serializer\Attribute\Groups;
12
13/**
14 * GET /api/users: every user with the privacy settings, for admins (the app's list of users).
15 */
16#[ApiResource(
17    shortName: 'User',
18    description: 'Every user with what they show to other users (visibleParts; visibilityChosen is false until they chose), for admins. Admins also get the profile picture of users who keep it private.',
19    operations: [
20        new GetCollection(
21            uriTemplate: '/users',
22            paginationEnabled: false,
23            security: "is_granted('ROLE_ADMIN')",
24            provider: UserPrivacyProvider::class,
25        ),
26    ],
27    normalizationContext: ['groups' => [self::READ]],
28)]
29final readonly class UserPrivacy
30{
31    public const string READ = 'user-privacy:read';
32
33    /**
34     * @param list<string> $visibleParts ProfilePart values
35     */
36    public function __construct(
37        #[ApiProperty(identifier: true)]
38        #[Groups([self::READ])]
39        public int $id,
40        #[Groups([self::READ])]
41        public string $identifier,
42        #[Groups([self::READ])]
43        public string $role,
44        #[Groups([self::READ])]
45        public ?string $agentName,
46        /** From the latest stats; null without stats. */
47        #[Groups([self::READ])]
48        public ?string $faction,
49        #[Groups([self::READ])]
50        public ?int $level,
51        #[Groups([self::READ])]
52        public ?string $avatar,
53        #[Groups([self::READ])]
54        public array $visibleParts,
55        #[Groups([self::READ])]
56        public bool $visibilityChosen,
57    ) {
58    }
59}