User::fromProperties()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0
cc 1
eloc 48
nc 1
nop 22

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Model;
23
24
/**
25
 * The user model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class User implements Model
30
{
31
    protected $shallowUser;
32
    protected $aboutMe;
33
    protected $accountId;
34
    protected $age;
35
    protected $answerCount;
36
    protected $creationDate;
37
    protected $displayName;
38
    protected $downVoteCount;
39
    protected $isEmployee;
40
    protected $lastAccessDate;
41
    protected $lastModifiedDate;
42
    protected $location;
43
    protected $questionCount;
44
    protected $reputationChangeDay;
45
    protected $reputationChangeMonth;
46
    protected $reputationChangeQuarter;
47
    protected $reputationChangeWeek;
48
    protected $reputationChangeYear;
49
    protected $timedPenaltyDate;
50
    protected $upVoteCount;
51
    protected $viewCount;
52
    protected $websiteUrl;
53
54
    public static function fromJson(array $data)
55
    {
56
        $instance = new self();
57
        $instance
58
            ->setShallowUser(ShallowUser::fromJson($data))
59
            ->setAboutMe(array_key_exists('about_me', $data) ? $data['about_me'] : null)
60
            ->setAccountId(array_key_exists('account_id', $data) ? $data['account_id'] : null)
61
            ->setAge(array_key_exists('age', $data) ? $data['age'] : null)
62
            ->setAnswerCount(array_key_exists('answer_count', $data) ? $data['answer_count'] : null)
63
            ->setCreationDate(
64
                array_key_exists('creation_date', $data)
65
                    ? new \DateTime('@' . $data['creation_date'])
66
                    : null
67
            )
68
            ->setDisplayName(array_key_exists('display_name', $data) ? $data['display_name'] : null)
69
            ->setDownVoteCount(array_key_exists('down_vote_count', $data) ? $data['down_vote_count'] : null)
70
            ->setIsEmployee(array_key_exists('is_employee', $data) ? $data['is_employee'] : null)
71
            ->setLastAccessDate(
72
                array_key_exists('last_access_date', $data)
73
                    ? new \DateTimeImmutable('@' . $data['last_access_date'])
74
                    : null
75
            )
76
            ->setLastModifiedDate(
77
                array_key_exists('last_modified_date', $data)
78
                    ? new \DateTimeImmutable('@' . $data['last_modified_date'])
79
                    : null
80
            )
81
            ->setLocation(array_key_exists('location', $data) ? $data['location'] : null)
82
            ->setQuestionCount(array_key_exists('question_count', $data) ? $data['question_count'] : null)
83
            ->setReputationChangeDay(
84
                array_key_exists('reputation_change_day', $data)
85
                    ? $data['reputation_change_day']
86
                    : null
87
            )
88
            ->setReputationChangeMonth(
89
                array_key_exists('reputation_change_month', $data)
90
                    ? $data['reputation_change_month']
91
                    : null
92
            )
93
            ->setReputationChangeQuarter(
94
                array_key_exists('reputation_change_quarter', $data)
95
                    ? $data['reputation_change_quarter']
96
                    : null
97
            )
98
            ->setReputationChangeWeek(
99
                array_key_exists('reputation_change_week', $data)
100
                    ? $data['reputation_change_week']
101
                    : null
102
            )
103
            ->setReputationChangeYear(
104
                array_key_exists('reputation_change_year', $data)
105
                    ? $data['reputation_change_year']
106
                    : null
107
            )
108
            ->setTimedPenaltyDate(
109
                array_key_exists('timed_penalty_date', $data)
110
                    ? new \DateTimeImmutable('@' . $data['timed_penalty_date'])
111
                    : null
112
            )
113
            ->setUpVoteCount(array_key_exists('up_vote_count', $data) ? $data['up_vote_count'] : null)
114
            ->setViewCount(array_key_exists('view_count', $data) ? $data['view_count'] : null)
115
            ->setWebsiteUrl(array_key_exists('website_url', $data) ? $data['website_url'] : null);
116
117
        return $instance;
118
    }
119
120
    public static function fromProperties(
121
        ShallowUser $shallowUser,
122
        $accountId,
123
        $answerCount,
124
        \DateTimeInterface $creationDate,
125
        $displayName,
126
        $downVoteCount,
127
        $isEmployee,
128
        \DateTimeInterface $lastAccessDate,
129
        $questionCount,
130
        $reputationChangeDay,
131
        $reputationChangeMonth,
132
        $reputationChangeQuarter,
133
        $reputationChangeWeek,
134
        $reputationChangeYear,
135
        $upVoteCount,
136
        $viewCount,
137
        $aboutMe = null,
138
        $age = null,
139
        \DateTimeInterface $lastModifiedDate = null,
140
        $location = null,
141
        \DateTimeInterface $timedPenaltyDate = null,
142
        $websiteUrl = null
143
    ) {
144
        $instance = new self();
145
        $instance
146
            ->setShallowUser($shallowUser)
147
            ->setAboutMe($aboutMe)
148
            ->setAccountId($accountId)
149
            ->setAge($age)
150
            ->setAnswerCount($answerCount)
151
            ->setCreationDate($creationDate)
152
            ->setDisplayName($displayName)
153
            ->setDownVoteCount($downVoteCount)
154
            ->setIsEmployee($isEmployee)
155
            ->setLastAccessDate($lastAccessDate)
156
            ->setLastModifiedDate($lastModifiedDate)
157
            ->setLocation($location)
158
            ->setQuestionCount($questionCount)
159
            ->setReputationChangeDay($reputationChangeDay)
160
            ->setReputationChangeMonth($reputationChangeMonth)
161
            ->setReputationChangeQuarter($reputationChangeQuarter)
162
            ->setReputationChangeWeek($reputationChangeWeek)
163
            ->setReputationChangeYear($reputationChangeYear)
164
            ->setTimedPenaltyDate($timedPenaltyDate)
165
            ->setUpVoteCount($upVoteCount)
166
            ->setViewCount($viewCount)
167
            ->setWebsiteUrl($websiteUrl);
168
169
        return $instance;
170
    }
171
172
    public function getShallowUser()
173
    {
174
        return $this->shallowUser;
175
    }
176
177
    public function setShallowUser(ShallowUser $shallowUser = null)
178
    {
179
        $this->shallowUser = $shallowUser;
180
181
        return $this;
182
    }
183
184
    public function getAboutMe()
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...
185
    {
186
        return $this->aboutMe;
187
    }
188
189
    public function setAboutMe($aboutMe)
190
    {
191
        $this->aboutMe = $aboutMe;
192
193
        return $this;
194
    }
195
196
    public function getAccountId()
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...
197
    {
198
        return $this->accountId;
199
    }
200
201
    public function setAccountId($accountId)
202
    {
203
        $this->accountId = $accountId;
204
205
        return $this;
206
    }
207
208
    public function getAge()
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...
209
    {
210
        return $this->age;
211
    }
212
213
    public function setAge($age)
214
    {
215
        $this->age = $age;
216
217
        return $this;
218
    }
219
220
    public function getAnswerCount()
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...
221
    {
222
        return $this->answerCount;
223
    }
224
225
    public function setAnswerCount($answerCount)
226
    {
227
        $this->answerCount = $answerCount;
228
229
        return $this;
230
    }
231
232
    public function getCreationDate()
233
    {
234
        return $this->creationDate;
235
    }
236
237
    public function setCreationDate(\DateTimeInterface $creationDate = null)
238
    {
239
        $this->creationDate = $creationDate;
240
241
        return $this;
242
    }
243
244
    public function getDisplayName()
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...
245
    {
246
        return $this->displayName;
247
    }
248
249
    public function setDisplayName($displayName)
250
    {
251
        $this->displayName = $displayName;
252
253
        return $this;
254
    }
255
256
    public function getDownVoteCount()
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...
257
    {
258
        return $this->downVoteCount;
259
    }
260
261
    public function setDownVoteCount($downVoteCount)
262
    {
263
        $this->downVoteCount = $downVoteCount;
264
265
        return $this;
266
    }
267
268
    public function getIsEmployee()
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...
269
    {
270
        return $this->isEmployee;
271
    }
272
273
    public function setIsEmployee($isEmployee)
274
    {
275
        $this->isEmployee = $isEmployee;
276
277
        return $this;
278
    }
279
280
    public function getLastAccessDate()
281
    {
282
        return $this->lastAccessDate;
283
    }
284
285
    public function setLastAccessDate(\DateTimeInterface $lastAccessDate = null)
286
    {
287
        $this->lastAccessDate = $lastAccessDate;
288
289
        return $this;
290
    }
291
292
    public function getLastModifiedDate()
293
    {
294
        return $this->lastModifiedDate;
295
    }
296
297
    public function setLastModifiedDate(\DateTimeInterface $lastModifiedDate = null)
298
    {
299
        $this->lastModifiedDate = $lastModifiedDate;
300
301
        return $this;
302
    }
303
304
    public function getLocation()
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...
305
    {
306
        return $this->location;
307
    }
308
309
    public function setLocation($location)
310
    {
311
        $this->location = $location;
312
313
        return $this;
314
    }
315
316
    public function getQuestionCount()
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...
317
    {
318
        return $this->questionCount;
319
    }
320
321
    public function setQuestionCount($questionCount)
322
    {
323
        $this->questionCount = $questionCount;
324
325
        return $this;
326
    }
327
328
    public function getReputationChangeDay()
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...
329
    {
330
        return $this->reputationChangeDay;
331
    }
332
333
    public function setReputationChangeDay($reputationChangeDay)
334
    {
335
        $this->reputationChangeDay = $reputationChangeDay;
336
337
        return $this;
338
    }
339
340
    public function getReputationChangeMonth()
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...
341
    {
342
        return $this->reputationChangeMonth;
343
    }
344
345
    public function setReputationChangeMonth($reputationChangeMonth)
346
    {
347
        $this->reputationChangeMonth = $reputationChangeMonth;
348
349
        return $this;
350
    }
351
352
    public function getReputationChangeQuarter()
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...
353
    {
354
        return $this->reputationChangeQuarter;
355
    }
356
357
    public function setReputationChangeQuarter($reputationChangeQuarter)
358
    {
359
        $this->reputationChangeQuarter = $reputationChangeQuarter;
360
361
        return $this;
362
    }
363
364
    public function getReputationChangeWeek()
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...
365
    {
366
        return $this->reputationChangeWeek;
367
    }
368
369
    public function setReputationChangeWeek($reputationChangeWeek)
370
    {
371
        $this->reputationChangeWeek = $reputationChangeWeek;
372
373
        return $this;
374
    }
375
376
    public function getReputationChangeYear()
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...
377
    {
378
        return $this->reputationChangeYear;
379
    }
380
381
    public function setReputationChangeYear($reputationChangeYear)
382
    {
383
        $this->reputationChangeYear = $reputationChangeYear;
384
385
        return $this;
386
    }
387
388
    public function getTimedPenaltyDate()
389
    {
390
        return $this->timedPenaltyDate;
391
    }
392
393
    public function setTimedPenaltyDate(\DateTimeInterface $timedPenaltyDate = null)
394
    {
395
        $this->timedPenaltyDate = $timedPenaltyDate;
396
397
        return $this;
398
    }
399
400
    public function getUpVoteCount()
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...
401
    {
402
        return $this->upVoteCount;
403
    }
404
405
    public function setUpVoteCount($upVoteCount)
406
    {
407
        $this->upVoteCount = $upVoteCount;
408
409
        return $this;
410
    }
411
412
    public function getViewCount()
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...
413
    {
414
        return $this->viewCount;
415
    }
416
417
    public function setViewCount($viewCount)
418
    {
419
        $this->viewCount = $viewCount;
420
421
        return $this;
422
    }
423
424
    public function getWebsiteUrl()
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...
425
    {
426
        return $this->websiteUrl;
427
    }
428
429
    public function setWebsiteUrl($websiteUrl)
430
    {
431
        $this->websiteUrl = $websiteUrl;
432
433
        return $this;
434
    }
435
}
436