Completed
Push — v2 ( 0c2cc9...f96eb8 )
by Beñat
05:19
created

User::fromProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 49
rs 9.2258
cc 1
eloc 46
nc 1
nop 22

How to fix   Many Parameters   

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