Completed
Push — master ( 9a78d5...7bc3e7 )
by Pol
02:13
created

CasUser   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Test Coverage

Coverage 92%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 12
eloc 13
c 3
b 0
f 0
dl 0
loc 106
ccs 23
cts 25
cp 0.92
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getUser() 0 3 1
A getStorage() 0 3 1
A getUsername() 0 3 1
A getSalt() 0 3 1
A getPassword() 0 3 1
A getPgt() 0 3 1
A get() 0 3 1
A getAttributes() 0 3 1
A getRoles() 0 3 1
A getAttribute() 0 3 1
A eraseCredentials() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\CasBundle\Security\Core\User;
6
7
use LogicException;
8
9
/**
10
 * Class CasUser.
11
 */
12
final class CasUser implements CasUserInterface
13
{
14
    /**
15
     * The user storage.
16
     *
17
     * @var array
18
     */
19
    private $storage;
20
21
    /**
22
     * CasUser constructor.
23
     *
24
     * @param array $data
25
     */
26 12
    public function __construct(array $data)
27
    {
28 12
        $this->storage = $data;
29 12
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function eraseCredentials(): void
35
    {
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 3
    public function get(string $key, $default = null)
42
    {
43 3
        return $this->getStorage()[$key] ?? $default;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 1
    public function getAttribute(string $key, $default = null)
50
    {
51 1
        return $this->getStorage()['attributes'][$key] ?? $default;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 1
    public function getAttributes(): array
58
    {
59 1
        return $this->get('attributes', []);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 1
    public function getPassword()
66
    {
67 1
        throw new LogicException('Not implemented.');
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 1
    public function getPgt(): ?string
74
    {
75 1
        return $this->get('proxyGrantingTicket');
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 1
    public function getRoles()
82
    {
83 1
        return ['ROLE_CAS_AUTHENTICATED'];
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 1
    public function getSalt()
90
    {
91 1
        throw new LogicException('Not implemented.');
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 1
    public function getUser(): string
98
    {
99 1
        return $this->get('user');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('user') could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105 1
    public function getUsername()
106
    {
107 1
        return $this->getUser();
108
    }
109
110
    /**
111
     * Get the storage.
112
     *
113
     * @return array
114
     */
115 4
    private function getStorage()
116
    {
117 4
        return $this->storage;
118
    }
119
}
120