Passed
Push — multiproject/local-access ( 5353e5 )
by Simon
04:56
created

UserRoleLoader::loadRolesForUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Security;
10
11
use Waca\DataObjects\Domain;
12
use Waca\DataObjects\User;
13
use Waca\DataObjects\UserRole;
14
15
final class UserRoleLoader implements IUserRoleLoader
16
{
17
    /**
18
     * Loads the roles for the given user in the current domain from the database.
19
     *
20
     * This is mostly just a wrapper around the static method calls so this logic
21
     * can be mocked out in unit tests.
22
     */
23
    public function loadRolesForUser(User $user): array
24
    {
25
        $domain = Domain::getCurrent($user->getDatabase());
26
        $userRoles = UserRole::getForUser($user->getId(), $user->getDatabase(), $domain->getId());
27
28
        return array_map(fn(UserRole $r): string => $r->getRole(), $userRoles);
29
    }
30
}