Completed
Pull Request — master (#1)
by Artem
03:18
created

User   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 237
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 237
ccs 0
cts 44
cp 0
rs 10
c 0
b 0
f 0
wmc 13

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getEmail() 0 3 1
A getRemoteAction() 0 3 1
A getName() 0 3 1
A getPassword() 0 3 1
A getDeleted() 0 3 1
A getCountry() 0 3 1
A resetPassword() 0 3 1
A getRemoteId() 0 3 1
A __construct() 0 21 2
A getCreated() 0 3 1
A getUpdated() 0 3 1
A createFromResponse() 0 14 1
1
<?php
2
3
namespace Slides\Connector\Auth\Sync;
4
5
use Carbon\Carbon;
6
7
/**
8
 * Class User describes a remote user
9
 *
10
 * @package Slides\Connector\Auth\Sync
11
 */
12
final class User
13
{
14
    /**
15
     * User's remote ID
16
     *
17
     * @var int
18
     */
19
    protected $remoteId;
20
21
    /**
22
     * User's name
23
     *
24
     * @var string
25
     */
26
    protected $name;
27
28
    /**
29
     * User's email
30
     *
31
     * @var string
32
     */
33
    protected $email;
34
35
    /**
36
     * User's country code
37
     *
38
     * @var string
39
     */
40
    protected $country;
41
42
    /**
43
     * User's encrypted password
44
     *
45
     * @var string
46
     */
47
    protected $password;
48
49
    /**
50
     * The date of last update.
51
     *
52
     * @var Carbon
53
     */
54
    protected $updated;
55
56
    /**
57
     * The creation date.
58
     *
59
     * @var Carbon
60
     */
61
    protected $created;
62
63
    /**
64
     * The deletion date.
65
     *
66
     * @var Carbon|null
67
     */
68
    protected $deleted;
69
70
    /**
71
     * The instance of the user locally
72
     *
73
     * @var \Illuminate\Contracts\Auth\Authenticatable
74
     */
75
    protected $localUser;
76
77
    /**
78
     * Whether a user exist only locally
79
     *
80
     * @var bool
81
     */
82
    protected $isLocal = false;
83
84
    /**
85
     * The action for a remote sync client
86
     *
87
     * @var string
88
     */
89
    protected $remoteAction;
90
91
    /**
92
     * User constructor.
93
     *
94
     * @param int $remoteId
95
     * @param string|null $name
96
     * @param string $email
97
     * @param string|null $password
98
     * @param string|null $updated
99
     * @param string $created
100
     * @param string|null $country
101
     * @param string|null $deleted
102
     * @param string $action
103
     */
104
    public function __construct(
105
        int $remoteId,
106
        ?string $name,
107
        string $email,
108
        ?string $password,
109
        ?string $updated,
110
        string $created,
111
        ?string $deleted,
112
        ?string $country,
113
        string $action = null
114
    )
115
    {
116
        $this->remoteId = $remoteId;
117
        $this->name = $name;
118
        $this->email = $email;
119
        $this->password = $password;
120
        $this->updated = new Carbon($updated);
121
        $this->created = new Carbon($created);
122
        $this->country = $country;
123
        $this->deleted = ($deleted ? new Carbon($deleted) : null);
124
        $this->remoteAction = $action;
125
    }
126
127
    /**
128
     * Get user's name
129
     *
130
     * @return string|null
131
     */
132
    public function getName()
133
    {
134
        return $this->name;
135
    }
136
137
    /**
138
     * Get user's email
139
     *
140
     * @return string
141
     */
142
    public function getEmail(): string
143
    {
144
        return $this->email;
145
    }
146
147
    /**
148
     * Get user's password
149
     *
150
     * @return string|null
151
     */
152
    public function getPassword()
153
    {
154
        return $this->password;
155
    }
156
157
    /**
158
     * Get a creation date.
159
     *
160
     * @return Carbon
161
     */
162
    public function getCreated(): Carbon
163
    {
164
        return $this->created;
165
    }
166
167
    /**
168
     * Get updated_at date
169
     *
170
     * @return Carbon|null
171
     */
172
    public function getUpdated()
173
    {
174
        return $this->updated;
175
    }
176
177
    /**
178
     * Get remote action
179
     *
180
     * @return string|null
181
     */
182
    public function getRemoteAction(): ?string
183
    {
184
        return $this->remoteAction;
185
    }
186
187
    /**
188
     * Get remote user ID
189
     *
190
     * @return int
191
     */
192
    public function getRemoteId(): int
193
    {
194
        return $this->remoteId;
195
    }
196
197
    /**
198
     * Get user's country
199
     *
200
     * @return string|null
201
     */
202
    public function getCountry()
203
    {
204
        return $this->country;
205
    }
206
207
    /**
208
     * Reset the password.
209
     *
210
     * @return void
211
     */
212
    public function resetPassword()
213
    {
214
        $this->password = null;
215
    }
216
217
    /**
218
     * Create a user from the response
219
     *
220
     * @param array $response
221
     *
222
     * @return static
223
     */
224
    public static function createFromResponse(array $response)
225
    {
226
        $user = array_get($response, 'user');
227
228
        return new static(
229
            array_get($user, 'id'),
0 ignored issues
show
Bug introduced by
It seems like array_get($user, 'id') can also be of type null; however, parameter $remoteId of Slides\Connector\Auth\Sync\User::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

229
            /** @scrutinizer ignore-type */ array_get($user, 'id'),
Loading history...
230
            array_get($user, 'name'),
231
            array_get($user, 'email'),
0 ignored issues
show
Bug introduced by
It seems like array_get($user, 'email') can also be of type null; however, parameter $email of Slides\Connector\Auth\Sync\User::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

231
            /** @scrutinizer ignore-type */ array_get($user, 'email'),
Loading history...
232
            array_get($user, 'password'),
233
            array_get($user, 'updated_at'),
234
            array_get($user, 'created_at'),
0 ignored issues
show
Bug introduced by
It seems like array_get($user, 'created_at') can also be of type null; however, parameter $created of Slides\Connector\Auth\Sync\User::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

234
            /** @scrutinizer ignore-type */ array_get($user, 'created_at'),
Loading history...
235
            array_get($user, 'deleted_at'),
236
            array_get($user, 'country'),
237
            array_get($user, 'action')
238
        );
239
    }
240
241
    /**
242
     * Get a deletion date.
243
     *
244
     * @return Carbon|null
245
     */
246
    public function getDeleted(): ?Carbon
247
    {
248
        return $this->deleted;
249
    }
250
}