Passed
Branch master (6982d9)
by Ivan
02:35
created

RolesProvider::getRoles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
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;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...en\Storage\TokenStorage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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