ApiGwAuthenticationUser::getAttribute()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @see https://github.com/ecphp
8
 */
9
10
declare(strict_types=1);
11
12
namespace EcPhp\ApiGwAuthenticationBundle\Security\Core\User;
13
14
final class ApiGwAuthenticationUser implements ApiGwAuthenticationUserInterface
15
{
16
    public string $sub;
17
18
    /**
19
     * The user storage.
20
     *
21
     * @var array<mixed>
22
     */
23
    private array $storage;
24
25
    /**
26
     * @param array<mixed> $data
27
     */
28 9
    public function __construct(string $username, array $data = [])
29
    {
30 9
        $this->sub = $username;
31 9
        $this->storage = $data;
32
    }
33
34 3
    public static function createFromPayload($username, array $payload)
35
    {
36 3
        return new self($username, $payload);
37
    }
38
39
    public function eraseCredentials(): void
40
    {
41
    }
42
43 1
    public function get(string $key, $default = null)
44
    {
45 1
        return $this->getStorage()[$key] ?? $default;
46
    }
47
48 1
    public function getAttribute(string $key, $default = null)
49
    {
50 1
        return $this->getStorage()[$key] ?? $default;
51
    }
52
53 1
    public function getAttributes(): array
54
    {
55 1
        return $this->getStorage();
56
    }
57
58 1
    public function getPassword(): ?string
59
    {
60 1
        return null;
61
    }
62
63 1
    public function getRoles(): array
64
    {
65 1
        return ['IS_AUTHENTICATED_FULLY'];
66
    }
67
68 1
    public function getSalt(): ?string
69
    {
70 1
        return null;
71
    }
72
73 2
    public function getUsername(): string
74
    {
75 2
        return $this->sub;
76
    }
77
78
    /**
79
     * Get the storage.
80
     *
81
     * @return array<mixed>
82
     */
83 3
    private function getStorage(): array
84
    {
85 3
        return $this->storage;
86
    }
87
}
88