Passed
Pull Request — master (#1620)
by Tarmo
63:23
created

RolesService   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 51
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 7
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Security/RolesService.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Security;
10
11
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
12
use function array_unique;
13
use function array_values;
14
15
/**
16
 * Class RolesService
17
 *
18
 * @package App\Security
19
 * @author TLe, Tarmo Leppänen <[email protected]>
20
 */
21
class RolesService
22
{
23
    public function __construct(
24
        private readonly RoleHierarchyInterface $roleHierarchy,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 24 at column 25
Loading history...
25
    ) {
26
    }
27
28
    /**
29
     * Helper method to get inherited roles for given roles.
30
     *
31
     * @param array<int, string> $roles
32
     *
33
     * @return array<int, string>
34
     */
35
    public function getInheritedRoles(array $roles): array
36
    {
37
        return array_values(array_unique($this->roleHierarchy->getReachableRoleNames($roles)));
38
    }
39
}
40