Completed
Push — master ( 5fa5de...689521 )
by Matze
03:31
created

UserVO::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4286
cc 1
eloc 7
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 ROLE_ADMIN = 'admin';
14
    const ROLE_USER  = 'user';
15
16
    const ROLES = [
17
        self::ROLE_ADMIN,
18
        self::ROLE_USER
19
    ];
20
21
    /**
22
     * @var integer
23
     */
24
    public $id;
25
26
    /**
27
     * @var string
28
     */
29
    public $username;
30
31
    /**
32
     * @var string
33
     */
34
    public $password_hash;
35
36
    /**
37
     * @var string
38
     */
39
    public $one_time_secret;
40
41
    /**
42
     * @var string
43
     */
44
    public $password;
45
46
    /**
47
     * @var string
48
     */
49
    public $email;
50
51
    /**
52
     * @var string[]
53
     */
54
    public $roles = [];
55
56
    /**
57
     * @var string
58
     */
59
    public $avatar;
60
61
    /**
62
     * @param string $role
63
     * @return boolean
64
     */
65 1
    public function hasRole($role)
66
    {
67 1
        return in_array($role, $this->roles);
68
    }
69
70
    /**
71
     * @return string[]
72
     */
73 1
    public function getRoles()
74
    {
75 1
        return $this->roles;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 1
    public function getPassword()
82
    {
83 1
        return $this->password_hash;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 1
    public function getSalt()
90
    {
91 1
        return $this->username;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 1
    public function getUsername()
98
    {
99 1
        return $this->username;
100
    }
101
102
    /**
103
     * @return array
104
     */
105 1
    public function jsonSerialize()
106
    {
107 1
        return $this->toArray();
108
    }
109
110
    /**
111
     * @return array
112
     */
113 1
    public function toArray()
114
    {
115
        return [
116 1
            'userId'   => $this->id,
117 1
            'username' => $this->username,
118 1
            'roles'    => $this->roles,
119 1
            'email'    => $this->email,
120 1
            'avatar'   => $this->avatar,
121
        ];
122
    }
123
}
124