KuleuvenUserToken   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 28 8
A getCredentials() 0 4 1
A getProviderKey() 0 4 1
1
<?php
2
3
namespace Kuleuven\AuthenticationBundle\Security;
4
5
use Kuleuven\AuthenticationBundle\Traits\ShibbolethAttributesResolverTrait;
6
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
7
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
10
class KuleuvenUserToken extends AbstractToken implements TokenInterface
11
{
12
    use ShibbolethAttributesResolverTrait;
13
14
    protected $providerKey;
15
16
    public function __construct($user = null, array $attributes = [], $providerKey, array $roles = [])
17
    {
18
        $this->setUser($user);
19
20
        $this->setAttributes($attributes);
21
22
        $this->providerKey = $providerKey;
23
24
        if (empty($roles) && $user instanceof UserInterface) {
25
            $roles = $user->getRoles();
26
        }
27
        if ($this->isStudent()) {
28
            $roles[] = 'ROLE_STUDENT';
29
        }
30
        if ($this->isEmployee()) {
31
            $roles[] = 'ROLE_EMPLOYEE';
32
        }
33
        if ($this->isFaculty()) {
34
            $roles[] = 'ROLE_FACULTY';
35
        }
36
        if ($this->isMember()) {
37
            $roles[] = 'ROLE_MEMBER';
38
        }
39
        if ($this->isStaff()) {
40
            $roles[] = 'ROLE_STAFF';
41
        }
42
        parent::__construct($roles);
43
    }
44
45
    public function getCredentials()
46
    {
47
        return '';
48
    }
49
50
    public function getProviderKey()
51
    {
52
        return $this->providerKey;
53
    }
54
}
55