Failed Conditions
Push — master ( 1bae70...6a9de1 )
by Florent
40:14
created

UserAccount::getSalt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace OAuth2Framework\ServerBundle\Tests\TestBundle\Entity;
15
16
use OAuth2Framework\Component\Core\ResourceOwner\ResourceOwnerId;
17
use OAuth2Framework\Component\Core\UserAccount\UserAccount as UserAccountInterface;
18
use OAuth2Framework\Component\Core\UserAccount\UserAccountId;
19
use Symfony\Component\Security\Core\User\EquatableInterface;
20
use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface;
21
22
final class UserAccount implements UserAccountInterface, SymfonyUserInterface, EquatableInterface
23
{
24
    private $username;
25
26
    /**
27
     * @var string[]
28
     */
29
    private $roles;
30
31
    private $lastLoginAt;
32
33
    private $lastUpdateAt;
34
35
    private $userAccountId;
36
37
    private $data = [];
38
39
    public function __construct(UserAccountId $userAccountId, string $username, array $roles, ?\DateTimeImmutable $lastLoginAt, ?\DateTimeImmutable $lastUpdateAt, array $data)
40
    {
41
        $this->userAccountId = $userAccountId;
42
        $this->username = $username;
43
        $this->roles = $roles;
44
        $this->lastLoginAt = $lastLoginAt;
45
        $this->lastUpdateAt = $lastUpdateAt;
46
        $this->data = $data;
47
    }
48
49
    public function getUserAccountId(): UserAccountId
50
    {
51
        return $this->userAccountId;
52
    }
53
54
    public function getPublicId(): ResourceOwnerId
55
    {
56
        return $this->userAccountId;
57
    }
58
59
    public function has(string $key): bool
60
    {
61
        return array_key_exists($key, $this->data);
62
    }
63
64
    public function get(string $key)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
65
    {
66
        if (!$this->has($key)) {
67
            throw new \InvalidArgumentException(\Safe\sprintf('The user account parameter "%s" does not exist.', $key));
68
        }
69
70
        return $this->data[$key];
71
    }
72
73
    public function getLastLoginAt(): ?int
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
74
    {
75
        return $this->lastLoginAt ? $this->lastLoginAt->getTimestamp() : null;
76
    }
77
78
    public function getLastUpdateAt(): ?int
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
79
    {
80
        return $this->lastUpdateAt ? $this->lastUpdateAt->getTimestamp() : null;
81
    }
82
83
    public function getRoles(): array
84
    {
85
        return $this->roles;
86
    }
87
88
    public function getSalt()
89
    {
90
        return;
91
    }
92
93
    public function getUsername(): string
94
    {
95
        return $this->username;
96
    }
97
98
    public function getPassword(): string
99
    {
100
        return '';
101
    }
102
103
    public function eraseCredentials()
104
    {
105
    }
106
107
    public function isEqualTo(SymfonyUserInterface $user)
108
    {
109
        if (!$user instanceof self) {
110
            return false;
111
        }
112
113
        if ($this->username !== $user->getUsername()) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($this->username... $user->getUsername());.
Loading history...
114
            return false;
115
        }
116
117
        return true;
118
    }
119
}
120