Completed
Push — master ( fd6c7c...1f9fde )
by Matze
09:32
created

UserVO::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace BrainExe\Core\Authentication;
4
5
use JsonSerializable;
6
7
/**
8
 * @api
9
 */
10
class UserVO implements JsonSerializable
11
{
12
13
    const PROPERTY_AVATAR = 'avatar';
14
    const PROPERTY_EMAIL  = 'email';
15
16
    const ROLE_ADMIN = 'admin';
17
    const ROLE_USER  = 'user';
18
19
    const AVATAR_1 = 'avatar1.png';
20
    const AVATAR_2 = 'avatar2.png';
21
    const AVATAR_3 = 'avatar3.png';
22
    const AVATAR_4 = 'avatar4.png';
23
    const AVATAR_5 = 'avatar5.png';
24
25
    const DEFAULT_AVATAR = self::AVATAR_5;
26
27
    const ROLES = [
28
        self::ROLE_ADMIN,
29
        self::ROLE_USER
30
    ];
31
32
    const AVATARS = [
33
        self::AVATAR_1,
34
        self::AVATAR_2,
35
        self::AVATAR_3,
36
        self::AVATAR_4,
37
        self::AVATAR_5,
38
    ];
39
40
    /**
41
     * @var int
42
     */
43
    public $id = 0;
44
45
    /**
46
     * @var string
47
     */
48
    public $username;
49
50
    /**
51
     * @var string
52
     */
53
    public $password_hash;
54
55
    /**
56
     * @var string
57
     */
58
    public $one_time_secret;
59
60
    /**
61
     * @var string
62
     */
63
    public $password;
64
65
    /**
66
     * @var string
67
     */
68
    public $email;
69
70
    /**
71
     * @var string[]
72
     */
73
    public $roles = [];
74
75
    /**
76
     * @var string
77
     */
78
    public $avatar;
79
80
    /**
81
     * @return int
82
     */
83 1
    public function getId() : int
84
    {
85 1
        return $this->id;
86
    }
87
88
    /**
89
     * @param string $role
90
     * @return bool
91
     */
92 1
    public function hasRole(string $role) : bool
93
    {
94 1
        return in_array($role, $this->roles);
95
    }
96
97
    /**
98
     * @return string[]
99
     */
100 1
    public function getRoles() : array
101
    {
102 1
        return $this->roles;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 1
    public function getPassword() :string
109
    {
110 1
        return $this->password_hash;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116 1
    public function getSalt()
117
    {
118 1
        return $this->username;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 1
    public function getUsername()
125
    {
126 1
        return $this->username;
127
    }
128
129
    /**
130
     * @return array
131
     */
132 1
    public function jsonSerialize()
133
    {
134 1
        return $this->toArray();
135
    }
136
137
    /**
138
     * @return array
139
     */
140 1
    public function toArray()
141
    {
142
        return [
143 1
            'userId'   => $this->id,
144 1
            'username' => $this->username,
145 1
            'roles'    => $this->roles,
146 1
            'email'    => $this->email,
147 1
            'avatar'   => $this->avatar,
148
        ];
149
    }
150
}
151