Lines 100.00% 17 / 17
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 provide 100.00% 16 / 16 100.00% 1 / 1 1
20final readonly class UserPrivacyProvider implements ProviderInterface
21{
22    public function __construct(
23        private UserRepository $userRepository,
24        private AgentStatRepository $agentStatRepository,
25    ) {
26    }
27
28    /**
29     * @return list<UserPrivacy>
30     */
31    public function provide(Operation $operation, array $uriVariables = [], array $context = []): array
32    {
33        $users = $this->userRepository->findAllByAgentName();
34        $latest = $this->agentStatRepository->findLatestByOwners($users);
35
36        return \array_values(\array_map(static function (User $user) use ($latest): UserPrivacy {
37            $stat = $latest[(int) $user->id] ?? null;
38
39            return new UserPrivacy(
40                (int) $user->id,
41                $user->getIdentifier(),
42                $user->getRole()->value,
43                $user->getAgentName(),
44                $stat?->faction,
45                $stat?->level,
46                $user->getAvatar(),
47                \array_map(static fn (ProfilePart $part): string => $part->value, $user->getVisibleParts()),
48                $user->getVisibilityChosenAt() instanceof \DateTimeImmutable,
49            );
50        }, $users));
51    }
52}