Passed
Push — master ( 81dab4...9aaa0a )
by Ivan
02:26
created

RolesProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 ['IS_AUTHENTICATED_ANONYMOUSLY'];
34
        }
35
    }
36
}
37