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

RolesProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getRoles() 0 9 2
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