Passed
Push — master ( 2bb211...a52526 )
by Pol
08:19
created

CasUser   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 68%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 103
ccs 17
cts 25
cp 0.68
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getPgt() 0 3 1
A getRoles() 0 3 1
A eraseCredentials() 0 2 1
A __construct() 0 3 1
A getPassword() 0 3 1
A getAttribute() 0 3 1
A isEqualTo() 0 3 1
A getUsername() 0 3 1
A get() 0 3 1
A getSalt() 0 3 1
A getStorage() 0 3 1
A getAttributes() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcPhp\CasBundle\Security\Core\User;
6
7
use Symfony\Component\Security\Core\User\UserInterface;
8
9
final class CasUser implements CasUserInterface
10
{
11
    /**
12
     * The user storage.
13
     *
14
     * @var array<mixed>
15
     */
16
    private array $storage;
17
18
    /**
19
     * CasUser constructor.
20
     *
21
     * @param array<mixed> $data
22
     */
23 9
    public function __construct(array $data)
24
    {
25 9
        $this->storage = $data;
26 9
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function eraseCredentials(): void
32
    {
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function get(string $key, $default = null)
39
    {
40 3
        return $this->getStorage()[$key] ?? $default;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function getAttribute(string $key, $default = null)
47
    {
48 1
        return $this->getStorage()['attributes'][$key] ?? $default;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function getAttributes(): array
55
    {
56 1
        return $this->get('attributes', []);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getPassword(): ?string
63
    {
64
        return null;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public function getPgt(): ?string
71
    {
72 1
        return $this->get('proxyGrantingTicket');
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 1
    public function getRoles(): array
79
    {
80 1
        return ['ROLE_CAS_AUTHENTICATED'];
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function getSalt(): ?string
87
    {
88
        return null;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function getUsername(): string
95
    {
96 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...
97
    }
98
99
    public function isEqualTo(UserInterface $user)
100
    {
101
        return $user->getUsername() === $this->getUsername();
102
    }
103
104
    /**
105
     * Get the storage.
106
     *
107
     * @return array<mixed>
108
     */
109 4
    private function getStorage(): array
110
    {
111 4
        return $this->storage;
112
    }
113
}
114