GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StaticProvider::getGroups()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 3
nop 1
1
<?php
2
3
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Server\Acl\Provider;
11
12
use SURFnet\VPN\Common\Config;
13
use SURFnet\VPN\Server\Acl\ProviderInterface;
14
15
class StaticProvider implements ProviderInterface
16
{
17
    /** @var \SURFnet\VPN\Common\Config */
18
    private $config;
19
20
    public function __construct(Config $config)
21
    {
22
        $this->config = $config;
23
    }
24
25
    /**
26
     * Get the groups a user is a member of.
27
     *
28
     * @param string userId the userID of the user to request the groups of
29
     *
30
     * @return array the groups as an array containing the keys "id" and
31
     *               "displayName", empty array if no groups are available for this user
32
     */
33
    public function getGroups($userId)
34
    {
35
        $memberOf = [];
36
37
        $groupIdList = array_keys($this->config->toArray());
38
        foreach ($groupIdList as $groupId) {
39
            $memberList = $this->config->getSection($groupId)->getSection('members')->toArray();
40
            if (!is_array($memberList) || !in_array($userId, $memberList)) {
41
                continue;
42
            }
43
44
            $memberOf[] = [
45
                'id' => $groupId,
46
                'displayName' => $this->config->getSection($groupId)->getItem('displayName'),
47
            ];
48
        }
49
50
        return $memberOf;
51
    }
52
}
53