Completed
Push — feature/EVO-6305_worker_authen... ( 500766...23d108 )
by Bastian
61:47
created

SecurityToken   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 27
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A hasRole() 0 17 4
1
<?php
2
/**
3
 * Enhanced PreAuthenticatedToken
4
 */
5
6
namespace Graviton\SecurityBundle\Authentication\Token;
7
8
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
9
use Symfony\Component\Security\Core\Role\Role;
10
11
/**
12
 * Class SecurityToken
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class SecurityToken extends PreAuthenticatedToken
19
{
20
    /**
21
     * Determines the token has the provided role.
22
     *
23
     * @param Role|string $role Role to be checked.
24
     *
25
     * @return boolean
26
     */
27
    public function hasRole($role)
28
    {
29
        $inList = false;
30
31
        if (is_string($role)) {
32
            $role = new Role($role);
33
        }
34
35
        foreach ($this->getRoles() as $listedRole) {
36
            if ($role->getRole() === $listedRole->getRole()) {
37
                $inList = true;
38
                break;
39
            }
40
        }
41
42
        return $inList;
43
    }
44
}
45