Completed
Push — v3 ( d12fea )
by Beñat
05:39
created

AnemicAnswer::setDownVoteCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2014-2016 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\Infrastructure\Domain\Model;
13
14
use BenatEspina\StackExchangeApiClient\Domain\Model\Answer;
15
use BenatEspina\StackExchangeApiClient\Domain\Model\ShallowUser;
16
17
/**
18
 * The anemic implementation of answer domain class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
class AnemicAnswer implements Answer
23
{
24
    private $id;
25
    private $accepted;
26
    private $awardedBountyAmount;
27
    private $awardedBountyUsers;
28
    private $canFlag;
29
    private $isAccepted;
30
    private $questionId;
31
    private $communityOwnedDate;
32
    private $lockedDate;
33
    private $tags;
34
    private $downvoted;
35
    private $lastActivityDate;
36
    private $shareLink;
37
    private $title;
38
    private $commentCount;
39
    private $comments;
40
    private $lastEditDate;
41
    private $lastEditor;
42
    private $downVoteCount;
43
    private $upVoteCount;
44
    private $body;
45
    private $bodyMarkDown;
46
    private $creationDate;
47
    private $link;
48
    private $owner;
49
    private $score;
50
    private $upvoted;
51
52
    public static function fromProperties(
53
        $id,
54
        $accepted,
55
        $canFlag,
56
        $isAccepted,
57
        $questionId,
58
        array $tags,
59
        $downvoted,
60
        \DateTimeInterface $lastActivityDate,
61
        $shareLink,
62
        $title,
63
        $commentCount,
64
        $downVoteCount,
65
        $upVoteCount,
66
        $body,
67
        $bodyMarkDown,
68
        \DateTimeInterface $creationDate,
69
        $link,
70
        $score,
71
        $upvoted,
72
        array $awardedBountyUsers = [],
73
        array $comments = [],
74
        $awardedBountyAmount = null,
75
        \DateTimeInterface $communityOwnedDate = null,
76
        ShallowUser $lastEditor = null,
77
        \DateTimeInterface $lastEditDate = null,
78
        \DateTimeInterface $lockedDate = null,
79
        ShallowUser $owner = null
80
    ) {
81
        return new self(
82
            $id,
83
            $accepted,
84
            $canFlag,
85
            $isAccepted,
86
            $questionId,
87
            $tags,
88
            $downvoted,
89
            $lastActivityDate,
90
            $shareLink,
91
            $title,
92
            $commentCount,
93
            $downVoteCount,
94
            $upVoteCount,
95
            $body,
96
            $bodyMarkDown,
97
            $creationDate,
98
            $link,
99
            $score,
100
            $upvoted,
101
            $comments,
102
            $awardedBountyUsers,
103
            $awardedBountyAmount,
104
            $communityOwnedDate,
105
            $lastEditor,
106
            $lastEditDate,
107
            $lockedDate,
108
            $owner
109
        );
110
    }
111
112
    public static function fromJson($data)
113
    {
114
        $tags = [];
115
        $awardedBountyUsers = [];
116
        $comments = [];
117
118 View Code Duplication
        if (array_key_exists('tags', $data) && is_array($data['tags'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
119
            foreach ($data['tags'] as $tag) {
120
                $tags[] = AnemicTag::fromJson($tag);
121
            }
122
        }
123 View Code Duplication
        if (array_key_exists('awarded_bounty_users', $data) && is_array($data['awarded_bounty_users'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
            foreach ($data['awarded_bounty_users'] as $awardedBountyUser) {
125
                $awardedBountyUsers[] = AnemicShallowUser::fromJson($awardedBountyUser);
126
            }
127
        }
128 View Code Duplication
        if (array_key_exists('comments', $data) && is_array($data['comments'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
            foreach ($data['comments'] as $comment) {
130
                $comments[] = AnemicComment::fromJson($comment);
131
            }
132
        }
133
134
        return new self(
135
            array_key_exists('answer_id', $data) ? $data['answer_id'] : null,
136
            array_key_exists('accepted', $data) ? $data['accepted'] : null,
137
            array_key_exists('can_flag', $data) ? $data['can_flag'] : null,
138
            array_key_exists('is_accepted', $data) ? $data['is_accepted'] : null,
139
            array_key_exists('question_id', $data) ? $data['question_id'] : null,
140
            $tags,
141
            array_key_exists('downvoted', $data) ? $data['downvoted'] : null,
142
            array_key_exists('last_activity_date', $data) ? new \DateTimeImmutable('@' . $data['last_activity_date']) : null,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
143
            array_key_exists('share_link', $data) ? $data['share_link'] : null,
144
            array_key_exists('title', $data) ? $data['title'] : null,
145
            array_key_exists('comment_count', $data) ? $data['comment_count'] : null,
146
            array_key_exists('down_vote_count', $data) ? $data['down_vote_count'] : null,
147
            array_key_exists('up_vote_count', $data) ? $data['up_vote_count'] : null,
148
            array_key_exists('body', $data) ? $data['body'] : null,
149
            array_key_exists('body_markdown', $data) ? $data['body_markdown'] : null,
150
            array_key_exists('creation_date', $data) ? new \DateTimeImmutable('@' . $data['creation_date']) : null,
151
            array_key_exists('link', $data) ? $data['link'] : null,
152
            array_key_exists('score', $data) ? $data['score'] : null,
153
            array_key_exists('upvoted', $data) ? $data['upvoted'] : null,
154
            $awardedBountyUsers,
155
            $comments,
156
            array_key_exists('awarded_bounty_amount', $data) ? $data['awarded_bounty_amount'] : null,
157
            array_key_exists('community_owned_date', $data) ? new \DateTimeImmutable('@' . $data['community_owned_date']) : null,
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
158
            array_key_exists('last_editor', $data) ? AnemicShallowUser::fromJson($data['last_editor']) : null,
159
            array_key_exists('last_edit_date', $data) ? new \DateTimeImmutable('@' . $data['last_edit_date']) : null,
160
            array_key_exists('locked_date', $data) ? new \DateTimeImmutable('@' . $data['locked_date']) : null,
161
            array_key_exists('owner', $data) ? AnemicShallowUser::fromJson($data['owner']) : null
162
        );
163
    }
164
165
    private function __construct(
166
        $id = null,
167
        $accepted = null,
168
        $canFlag = null,
169
        $isAccepted = null,
170
        $questionId = null,
171
        array $tags = [],
172
        $downvoted = null,
173
        \DateTimeInterface $lastActivityDate = null,
174
        $shareLink = null,
175
        $title = null,
176
        $commentCount = null,
177
        $downVoteCount = null,
178
        $upVoteCount = null,
179
        $body = null,
180
        $bodyMarkDown = null,
181
        \DateTimeInterface $creationDate = null,
182
        $link = null,
183
        $score = null,
184
        $upvoted = null,
185
        array $awardedBountyUsers = [],
186
        array $comments = [],
187
        $awardedBountyAmount = null,
188
        \DateTimeInterface $communityOwnedDate = null,
189
        ShallowUser $lastEditor = null,
190
        \DateTimeInterface $lastEditDate = null,
191
        \DateTimeInterface $lockedDate = null,
192
        ShallowUser $owner = null
193
    ) {
194
        $this->id = $id;
195
        $this->accepted = $accepted;
196
        $this->awardedBountyAmount = $awardedBountyAmount;
197
        $this->awardedBountyUsers = $awardedBountyUsers;
198
        $this->canFlag = $canFlag;
199
        $this->isAccepted = $isAccepted;
200
        $this->questionId = $questionId;
201
        $this->communityOwnedDate = $communityOwnedDate;
202
        $this->lockedDate = $lockedDate;
203
        $this->tags = $tags;
204
        $this->downvoted = $downvoted;
205
        $this->lastActivityDate = $lastActivityDate;
206
        $this->shareLink = $shareLink;
207
        $this->title = $title;
208
        $this->commentCount = $commentCount;
209
        $this->comments = $comments;
210
        $this->lastEditDate = $lastEditDate;
211
        $this->lastEditor = $lastEditor;
212
        $this->downVoteCount = $downVoteCount;
213
        $this->upVoteCount = $upVoteCount;
214
        $this->body = $body;
215
        $this->bodyMarkDown = $bodyMarkDown;
216
        $this->creationDate = $creationDate;
217
        $this->link = $link;
218
        $this->owner = $owner;
219
        $this->score = $score;
220
        $this->upvoted = $upvoted;
221
    }
222
223
    public function getId()
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...
224
    {
225
        return $this->id;
226
    }
227
228
    public function setId($id)
229
    {
230
        $this->id = $id;
231
232
        return $this;
233
    }
234
235
    public function getAccepted()
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...
236
    {
237
        return $this->accepted;
238
    }
239
240
    public function setAccepted($accepted)
241
    {
242
        $this->accepted = $accepted;
243
244
        return $this;
245
    }
246
247
    public function getAwardedBountyAmount()
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...
248
    {
249
        return $this->awardedBountyAmount;
250
    }
251
252
    public function setAwardedBountyAmount($awardedBountyAmount)
253
    {
254
        $this->awardedBountyAmount = $awardedBountyAmount;
255
256
        return $this;
257
    }
258
259
    public function getAwardedBountyUsers()
260
    {
261
        return $this->awardedBountyUsers;
262
    }
263
264
    public function setAwardedBountyUsers($awardedBountyUsers)
265
    {
266
        $this->awardedBountyUsers = $awardedBountyUsers;
267
268
        return $this;
269
    }
270
271
    public function getCanFlag()
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...
272
    {
273
        return $this->canFlag;
274
    }
275
276
    public function setCanFlag($canFlag)
277
    {
278
        $this->canFlag = $canFlag;
279
280
        return $this;
281
    }
282
283
    public function getIsAccepted()
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...
284
    {
285
        return $this->isAccepted;
286
    }
287
288
    public function setIsAccepted($isAccepted)
289
    {
290
        $this->isAccepted = $isAccepted;
291
292
        return $this;
293
    }
294
295
    public function getQuestionId()
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...
296
    {
297
        return $this->questionId;
298
    }
299
300
    public function setQuestionId($questionId)
301
    {
302
        $this->questionId = $questionId;
303
304
        return $this;
305
    }
306
307
    public function getCommunityOwnedDate()
308
    {
309
        return $this->communityOwnedDate;
310
    }
311
312
    public function setCommunityOwnedDate(\DateTimeInterface $communityOwnedDate)
313
    {
314
        $this->communityOwnedDate = $communityOwnedDate;
315
316
        return $this;
317
    }
318
319
    public function getLockedDate()
320
    {
321
        return $this->lockedDate;
322
    }
323
324
    public function setLockedDate(\DateTimeInterface $lockedDate)
325
    {
326
        $this->lockedDate = $lockedDate;
327
328
        return $this;
329
    }
330
331
    public function getTags()
332
    {
333
        return $this->tags;
334
    }
335
336
    public function setTags(array $tags)
337
    {
338
        $this->tags = $tags;
339
340
        return $this;
341
    }
342
343
    public function getDownvoted()
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...
344
    {
345
        return $this->downvoted;
346
    }
347
348
    public function setDownvoted($downvoted)
349
    {
350
        $this->downvoted = $downvoted;
351
352
        return $this;
353
    }
354
355
    public function getLastActivityDate()
356
    {
357
        return $this->lastActivityDate;
358
    }
359
360
    public function setLastActivityDate(\DateTimeInterface $lastActivityDate)
361
    {
362
        $this->lastActivityDate = $lastActivityDate;
363
364
        return $this;
365
    }
366
367
    public function getShareLink()
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...
368
    {
369
        return $this->shareLink;
370
    }
371
372
    public function setShareLink($shareLink)
373
    {
374
        $this->shareLink = $shareLink;
375
376
        return $this;
377
    }
378
379
    public function getTitle()
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...
380
    {
381
        return $this->title;
382
    }
383
384
    public function setTitle($title)
385
    {
386
        $this->title = $title;
387
388
        return $this;
389
    }
390
391
    public function getCommentCount()
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...
392
    {
393
        return $this->commentCount;
394
    }
395
396
    public function setCommentCount($commentCount)
397
    {
398
        $this->commentCount = $commentCount;
399
400
        return $this;
401
    }
402
403
    public function getComments()
404
    {
405
        return $this->comments;
406
    }
407
408
    public function setComments(array $comments)
409
    {
410
        $this->comments = $comments;
411
412
        return $this;
413
    }
414
415
    public function getLastEditDate()
416
    {
417
        return $this->lastEditDate;
418
    }
419
420
    public function setLastEditDate(\DateTimeInterface $lastEditDate)
421
    {
422
        $this->lastEditDate = $lastEditDate;
423
424
        return $this;
425
    }
426
427
    public function getLastEditor()
428
    {
429
        return $this->lastEditor;
430
    }
431
432
    public function setLastEditor(ShallowUser $lastEditor)
433
    {
434
        $this->lastEditor = $lastEditor;
435
436
        return $this;
437
    }
438
439
    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...
440
    {
441
        return $this->downVoteCount;
442
    }
443
444
    public function setDownVoteCount($downVoteCount)
445
    {
446
        $this->downVoteCount = $downVoteCount;
447
448
        return $this;
449
    }
450
451
    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...
452
    {
453
        return $this->upVoteCount;
454
    }
455
456
    public function setUpVoteCount($upVoteCount)
457
    {
458
        $this->upVoteCount = $upVoteCount;
459
460
        return $this;
461
    }
462
463
    public function getBody()
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...
464
    {
465
        return $this->body;
466
    }
467
468
    public function setBody($body)
469
    {
470
        $this->body = $body;
471
472
        return $this;
473
    }
474
475
    public function getBodyMarkDown()
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...
476
    {
477
        return $this->bodyMarkDown;
478
    }
479
480
    public function setBodyMarkDown($bodyMarkDown)
481
    {
482
        $this->bodyMarkDown = $bodyMarkDown;
483
484
        return $this;
485
    }
486
487
    public function getCreationDate()
488
    {
489
        return $this->creationDate;
490
    }
491
492
    public function setCreationDate(\DateTimeInterface $creationDate)
493
    {
494
        $this->creationDate = $creationDate;
495
496
        return $this;
497
    }
498
499
    public function getLink()
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...
500
    {
501
        return $this->link;
502
    }
503
504
    public function setLink($link)
505
    {
506
        $this->link = $link;
507
508
        return $this;
509
    }
510
511
    public function getOwner()
512
    {
513
        return $this->owner;
514
    }
515
516
    public function setOwner($owner)
517
    {
518
        $this->owner = $owner;
519
520
        return $this;
521
    }
522
523
    public function getScore()
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...
524
    {
525
        return $this->score;
526
    }
527
528
    public function setScore($score)
529
    {
530
        $this->score = $score;
531
532
        return $this;
533
    }
534
535
    public function getUpvoted()
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...
536
    {
537
        return $this->upvoted;
538
    }
539
540
    public function setUpvoted($upvoted)
541
    {
542
        $this->upvoted = $upvoted;
543
544
        return $this;
545
    }
546
}
547