Passed
Push — master ( a6aaea...9fd3bc )
by Pol
04:37
created

CasUser::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcPhp\CasBundle\Security\Core\User;
6
7
/**
8
 * Class CasUser.
9
 */
10
final class CasUser implements CasUserInterface
11
{
12
    /**
13
     * The user storage.
14
     *
15
     * @var array<mixed>
16
     */
17
    private $storage;
18
19
    /**
20
     * CasUser constructor.
21
     *
22
     * @param array<mixed> $data
23
     */
24 9
    public function __construct(array $data)
25
    {
26 9
        $this->storage = $data;
27 9
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function eraseCredentials(): void
33
    {
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 3
    public function get(string $key, $default = null)
40
    {
41 3
        return $this->getStorage()[$key] ?? $default;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 1
    public function getAttribute(string $key, $default = null)
48
    {
49 1
        return $this->getStorage()['attributes'][$key] ?? $default;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 1
    public function getAttributes(): array
56
    {
57 1
        return $this->get('attributes', []);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getPassword(): ?string
64
    {
65
        return null;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 1
    public function getPgt(): ?string
72
    {
73 1
        return $this->get('proxyGrantingTicket');
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 1
    public function getRoles(): array
80
    {
81 1
        return ['ROLE_CAS_AUTHENTICATED'];
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function getSalt(): ?string
88
    {
89
        return null;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 1
    public function getUser(): string
96
    {
97 1
        trigger_deprecation(
98 1
            'ecphp/cas-bundle',
99 1
            '2.1.2',
100 1
            'The method "%s::getUser()" is deprecated, use %s::getUsername() instead.',
101 1
            CasUserInterface::class
102
        );
103
104 1
        return $this->getUsername();
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110 1
    public function getUsername(): string
111
    {
112 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...
113
    }
114
115
    /**
116
     * Get the storage.
117
     *
118
     * @return array<mixed>
119
     */
120 4
    private function getStorage(): array
121
    {
122 4
        return $this->storage;
123
    }
124
}
125