Passed
Push — 1.0 ( 07d681...376964 )
by Pol
03:57
created

CasUser   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 56.67%

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 110
ccs 17
cts 30
cp 0.5667
rs 10
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A eraseCredentials() 0 2 1
A __construct() 0 3 1
A getAttribute() 0 3 1
A get() 0 3 1
A getAttributes() 0 3 1
A getPassword() 0 3 1
A getUsername() 0 3 1
A getSalt() 0 3 1
A getUser() 0 10 1
A getPgt() 0 3 1
A getStorage() 0 3 1
A getRoles() 0 3 1
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 (array) $this->get('attributes', []);
58
    }
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
     * @return string[]
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
    public function getUser(): string
93
    {
94
        trigger_deprecation(
0 ignored issues
show
Bug introduced by
The function trigger_deprecation was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        /** @scrutinizer ignore-call */ 
95
        trigger_deprecation(
Loading history...
95
            'ecphp/cas-bundle',
96
            '2.1.2',
97
            'The method "%s::getUser()" is deprecated, use %s::getUsername() instead.',
98
            CasUserInterface::class
99
        );
100
101
        return $this->getUsername();
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 1
    public function getUsername(): string
108
    {
109 1
        return $this->get('user');
110
    }
111
112
    /**
113
     * Get the storage.
114
     *
115
     * @return array<mixed>
116
     */
117 4
    private function getStorage(): array
118
    {
119 4
        return $this->storage;
120
    }
121
}
122