Lines 100.00% 15 / 15
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 getAllUsersForTemplate 100.00% 14 / 14 100.00% 1 / 1 3
29readonly class UserHelper
30{
31    /**
32     * UserHelper constructor.
33     */
34    public function __construct(
35        private User $user,
36    ) {
37    }
38
39    /**
40     * Get all users in <option> tags.
41     *
42     * @param int  $selectedId Selected user ID
43     * @param bool $allowBlockedUsers Allow blocked users as well, e.g., in admin
44     * @return array Array of users with 'id', 'selected', 'displayName', and 'login' keys
45     */
46    public function getAllUsersForTemplate(int $selectedId = 1, bool $allowBlockedUsers = false): array
47    {
48        $users = [];
49        $user = clone $this->user;
50        $allUserIds = $user->getAllUsers(true, $allowBlockedUsers);
51
52        foreach ($allUserIds as $allUserId) {
53            if ($allUserId === -1) {
54                continue;
55            }
56
57            $user->getUserById($allUserId);
58            $users[] = [
59                'id' => $allUserId,
60                'selected' => $allUserId === $selectedId,
61                'displayName' => $user->getUserData('display_name'),
62                'login' => $user->getLogin(),
63            ];
64        }
65
66        return $users;
67    }
68}