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.

SiteAccessGroupVoter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A vote() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Voter;
6
7
use function in_array;
8
9
final class SiteAccessGroupVoter implements VoterInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $groupsBySiteAccess;
15
16
    public function __construct(array $groupsBySiteAccess)
17
    {
18
        $this->groupsBySiteAccess = $groupsBySiteAccess;
19
    }
20
21
    /**
22
     * Returns if provided siteaccess is allowed based on passed route config.
23
     */
24
    public function vote(string $siteAccess, array $routeConfig): ?bool
25
    {
26
        // We skip the check if siteaccess is not part of any group
27
        if (!isset($this->groupsBySiteAccess[$siteAccess])) {
28
            return VoterInterface::ABSTAIN;
29
        }
30
31
        // We allow the siteaccess if any group to which the siteaccess belongs
32
        // is in the list of allowed siteaccesses
33
        foreach ($this->groupsBySiteAccess[$siteAccess] as $group) {
34
            if (in_array($group, $routeConfig, true)) {
35
                return true;
36
            }
37
        }
38
39
        return VoterInterface::ABSTAIN;
40
    }
41
}
42