RolesProvider::getRoles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\NavigationBundle\Bridge\Filter;
6
7
use Everlution\Navigation\Filter\RolesProviderInterface;
8
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
9
10
/**
11
 * Class RolesProvider.
12
 *
13
 * @author Ivan Barlog <[email protected]>
14
 */
15
class RolesProvider implements RolesProviderInterface
16
{
17
    /** @var TokenStorage */
18
    private $tokenStorage;
19
20
    public function __construct(TokenStorage $tokenStorage)
21
    {
22
        $this->tokenStorage = $tokenStorage;
23
    }
24
25
    public function getRoles(): array
26
    {
27
        try {
28
            return array_merge(
29
                $this->tokenStorage->getToken()?->getUser()?->getRoles(),
30
                ['IS_AUTHENTICATED_FULLY']
31
            );
32
        } catch (\Exception $exception) {
33
            return ['PUBLIC_ACCESS'];
34
        }
35
    }
36
}
37