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

UserVO   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 0 Features 3
Metric Value
wmc 7
c 7
b 0
f 3
lcom 1
cbo 0
dl 0
loc 114
ccs 18
cts 18
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasRole() 0 4 1
A getRoles() 0 4 1
A getPassword() 0 4 1
A getSalt() 0 4 1
A getUsername() 0 4 1
A jsonSerialize() 0 4 1
A toArray() 0 10 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