Passed
Push — master ( 66c18a...043c10 )
by Pol
22:47 queued 20:11
created

ApiGwAuthenticationUser::createFromPayload()   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
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
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
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