Passed
Pull Request — master (#7)
by Pol
22:18 queued 20:04
created

ApiGwAuthenticationUser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 14
dl 0
loc 96
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

11 Methods

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