Passed
Pull Request — master (#5)
by Ivan
01:48
created

RolesProvider::getRoles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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