Passed
Push — master ( 2c4349...5c635f )
by Pol
21:59 queued 19:27
created

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