SecurityContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 41
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getToken() 0 4 1
A setToken() 0 4 1
A isGranted() 0 14 3
1
<?php
2
3
namespace TreeHouse\BaseApiBundle\Security;
4
5
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
6
use Symfony\Component\Security\Core\SecurityContextInterface;
7
8
/**
9
 * A custom security context to hold information about the current user that the api client is acting on behalf of.
10
 */
11
class SecurityContext implements SecurityContextInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Symfony\Component\Securi...ecurityContextInterface has been deprecated with message: since version 2.6, to be removed in 3.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    /**
14
     * @var TokenInterface
15
     */
16
    protected $token;
17
18
    /**
19
     * @inheritdoc
20
     */
21 4
    public function getToken()
22
    {
23 4
        return $this->token;
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 2
    public function setToken(TokenInterface $token = null)
30
    {
31 2
        $this->token = $token;
32 2
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37 6
    public function isGranted($attributes, $object = null)
38
    {
39 6
        if (!is_array($attributes)) {
40 4
            $attributes = [$attributes];
41 2
        }
42
43 6
        if (null === $object) {
44 2
            $object = $this->token->getUser();
45 1
        }
46
47 6
        $acceptedRoles = array_intersect($attributes, $object->getRoles());
48
49 6
        return (0 !== count($acceptedRoles));
50
    }
51
}
52