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

Answer::getAccepted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 answer model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class Answer
20
{
21
    private $id;
22
    private $accepted;
23
    private $awardedBountyAmount;
24
    private $awardedBountyUsers;
25
    private $canFlag;
26
    private $isAccepted;
27
    private $questionId;
28
    private $communityOwnedDate;
29
    private $lockedDate;
30
    private $tags;
31
    private $downvoted;
32
    private $lastActivityDate;
33
    private $shareLink;
34
    private $title;
35
    private $commentCount;
36
    private $comments;
37
    private $lastEditDate;
38
    private $lastEditor;
39
    private $downVoteCount;
40
    private $upVoteCount;
41
    private $body;
42
    private $bodyMarkDown;
43
    private $creationDate;
44
    private $link;
45
    private $owner;
46
    private $score;
47
    private $upvoted;
48
49
    public static function fromProperties(
50
        $id,
51
        $accepted,
52
        $canFlag,
53
        $isAccepted,
54
        $questionId,
55
        array $tags,
56
        $downvoted,
57
        \DateTime $lastActivityDate,
58
        $shareLink,
59
        $title,
60
        $commentCount,
61
        $downVoteCount,
62
        $upVoteCount,
63
        $body,
64
        $bodyMarkDown,
65
        \DateTime $creationDate,
66
        $link,
67
        $score,
68
        $upvoted,
69
        array $awardedBountyUsers = [],
70
        array $comments = [],
71
        $awardedBountyAmount = null,
72
        \DateTime $communityOwnedDate = null,
73
        ShallowUser $lastEditor = null,
74
        \DateTime $lastEditDate = null,
75
        \DateTime $lockedDate = null,
76
        ShallowUser $owner = null
77
    ) {
78
        return new self(
79
            $id,
80
            $accepted,
81
            $canFlag,
82
            $isAccepted,
83
            $questionId,
84
            $tags,
85
            $downvoted,
86
            $lastActivityDate,
87
            $shareLink,
88
            $title,
89
            $commentCount,
90
            $downVoteCount,
91
            $upVoteCount,
92
            $body,
93
            $bodyMarkDown,
94
            $creationDate,
95
            $link,
96
            $score,
97
            $upvoted,
98
            $comments,
99
            $awardedBountyUsers,
100
            $awardedBountyAmount,
101
            $communityOwnedDate,
102
            $lastEditor,
103
            $lastEditDate,
104
            $lockedDate,
105
            $owner
106
        );
107
    }
108
109
    public static function fromJson(array $data)
110
    {
111
        $tags = [];
112
        $awardedBountyUsers = [];
113
        $comments = [];
114
115 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...
116
            foreach ($data['tags'] as $tag) {
117
                $tags[] = Tag::fromJson($tag);
118
            }
119
        }
120 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...
121
            foreach ($data['awarded_bounty_users'] as $awardedBountyUser) {
122
                $awardedBountyUsers[] = ShallowUser::fromJson($awardedBountyUser);
123
            }
124
        }
125 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...
126
            foreach ($data['comments'] as $comment) {
127
                $comments[] = Comment::fromJson($comment);
128
            }
129
        }
130
131
        return new self(
132
            array_key_exists('answer_id', $data) ? $data['answer_id'] : null,
133
            array_key_exists('accepted', $data) ? $data['accepted'] : null,
134
            array_key_exists('can_flag', $data) ? $data['can_flag'] : null,
135
            array_key_exists('is_accepted', $data) ? $data['is_accepted'] : null,
136
            array_key_exists('question_id', $data) ? $data['question_id'] : null,
137
            $tags,
138
            array_key_exists('downvoted', $data) ? $data['downvoted'] : null,
139
            array_key_exists('last_activity_date', $data) ? new \DateTime('@' . $data['last_activity_date']) : null,
140
            array_key_exists('share_link', $data) ? $data['share_link'] : null,
141
            array_key_exists('title', $data) ? $data['title'] : null,
142
            array_key_exists('comment_count', $data) ? $data['comment_count'] : null,
143
            array_key_exists('down_vote_count', $data) ? $data['down_vote_count'] : null,
144
            array_key_exists('up_vote_count', $data) ? $data['up_vote_count'] : null,
145
            array_key_exists('body', $data) ? $data['body'] : null,
146
            array_key_exists('body_markdown', $data) ? $data['body_markdown'] : null,
147
            array_key_exists('creation_date', $data) ? new \DateTime('@' . $data['creation_date']) : null,
148
            array_key_exists('link', $data) ? $data['link'] : null,
149
            array_key_exists('score', $data) ? $data['score'] : null,
150
            array_key_exists('upvoted', $data) ? $data['upvoted'] : null,
151
            $awardedBountyUsers,
152
            $comments,
153
            array_key_exists('awarded_bounty_amount', $data) ? $data['awarded_bounty_amount'] : null,
154
            array_key_exists('community_owned_date', $data) ? new \DateTime('@' . $data['community_owned_date']) : null,
155
            array_key_exists('last_editor', $data) ? ShallowUser::fromJson($data['last_editor']) : null,
156
            array_key_exists('last_edit_date', $data) ? new \DateTime('@' . $data['last_edit_date']) : null,
157
            array_key_exists('locked_date', $data) ? new \DateTime('@' . $data['locked_date']) : null,
158
            array_key_exists('owner', $data) ? ShallowUser::fromJson($data['owner']) : null
159
        );
160
    }
161
162
    private function __construct(
163
        $id = null,
164
        $accepted = null,
165
        $canFlag = null,
166
        $isAccepted = null,
167
        $questionId = null,
168
        array $tags = [],
169
        $downvoted = null,
170
        \DateTime $lastActivityDate = null,
171
        $shareLink = null,
172
        $title = null,
173
        $commentCount = null,
174
        $downVoteCount = null,
175
        $upVoteCount = null,
176
        $body = null,
177
        $bodyMarkDown = null,
178
        \DateTime $creationDate = null,
179
        $link = null,
180
        $score = null,
181
        $upvoted = null,
182
        array $awardedBountyUsers = [],
183
        array $comments = [],
184
        $awardedBountyAmount = null,
185
        \DateTime $communityOwnedDate = null,
186
        ShallowUser $lastEditor = null,
187
        \DateTime $lastEditDate = null,
188
        \DateTime $lockedDate = null,
189
        ShallowUser $owner = null
190
    ) {
191
        $this->id = $id;
192
        $this->accepted = $accepted;
193
        $this->awardedBountyAmount = $awardedBountyAmount;
194
        $this->awardedBountyUsers = $awardedBountyUsers;
195
        $this->canFlag = $canFlag;
196
        $this->isAccepted = $isAccepted;
197
        $this->questionId = $questionId;
198
        $this->communityOwnedDate = $communityOwnedDate;
199
        $this->lockedDate = $lockedDate;
200
        $this->tags = $tags;
201
        $this->downvoted = $downvoted;
202
        $this->lastActivityDate = $lastActivityDate;
203
        $this->shareLink = $shareLink;
204
        $this->title = $title;
205
        $this->commentCount = $commentCount;
206
        $this->comments = $comments;
207
        $this->lastEditDate = $lastEditDate;
208
        $this->lastEditor = $lastEditor;
209
        $this->downVoteCount = $downVoteCount;
210
        $this->upVoteCount = $upVoteCount;
211
        $this->body = $body;
212
        $this->bodyMarkDown = $bodyMarkDown;
213
        $this->creationDate = $creationDate;
214
        $this->link = $link;
215
        $this->owner = $owner;
216
        $this->score = $score;
217
        $this->upvoted = $upvoted;
218
    }
219
220
    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...
221
    {
222
        return $this->id;
223
    }
224
225
    public function setId($id)
226
    {
227
        $this->id = $id;
228
229
        return $this;
230
    }
231
232
    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...
233
    {
234
        return $this->accepted;
235
    }
236
237
    public function setAccepted($accepted)
238
    {
239
        $this->accepted = $accepted;
240
241
        return $this;
242
    }
243
244
    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...
245
    {
246
        return $this->awardedBountyAmount;
247
    }
248
249
    public function setAwardedBountyAmount($awardedBountyAmount)
250
    {
251
        $this->awardedBountyAmount = $awardedBountyAmount;
252
253
        return $this;
254
    }
255
256
    public function getAwardedBountyUsers()
257
    {
258
        return $this->awardedBountyUsers;
259
    }
260
261
    public function setAwardedBountyUsers($awardedBountyUsers)
262
    {
263
        $this->awardedBountyUsers = $awardedBountyUsers;
264
265
        return $this;
266
    }
267
268
    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...
269
    {
270
        return $this->canFlag;
271
    }
272
273
    public function setCanFlag($canFlag)
274
    {
275
        $this->canFlag = $canFlag;
276
277
        return $this;
278
    }
279
280
    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...
281
    {
282
        return $this->isAccepted;
283
    }
284
285
    public function setIsAccepted($isAccepted)
286
    {
287
        $this->isAccepted = $isAccepted;
288
289
        return $this;
290
    }
291
292
    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...
293
    {
294
        return $this->questionId;
295
    }
296
297
    public function setQuestionId($questionId)
298
    {
299
        $this->questionId = $questionId;
300
301
        return $this;
302
    }
303
304
    public function getCommunityOwnedDate()
305
    {
306
        return $this->communityOwnedDate;
307
    }
308
309
    public function setCommunityOwnedDate(\DateTime $communityOwnedDate)
310
    {
311
        $this->communityOwnedDate = $communityOwnedDate;
312
313
        return $this;
314
    }
315
316
    public function getLockedDate()
317
    {
318
        return $this->lockedDate;
319
    }
320
321
    public function setLockedDate(\DateTime $lockedDate)
322
    {
323
        $this->lockedDate = $lockedDate;
324
325
        return $this;
326
    }
327
328
    public function getTags()
329
    {
330
        return $this->tags;
331
    }
332
333
    public function setTags(array $tags)
334
    {
335
        $this->tags = $tags;
336
337
        return $this;
338
    }
339
340
    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...
341
    {
342
        return $this->downvoted;
343
    }
344
345
    public function setDownvoted($downvoted)
346
    {
347
        $this->downvoted = $downvoted;
348
349
        return $this;
350
    }
351
352
    public function getLastActivityDate()
353
    {
354
        return $this->lastActivityDate;
355
    }
356
357
    public function setLastActivityDate(\DateTime $lastActivityDate)
358
    {
359
        $this->lastActivityDate = $lastActivityDate;
360
361
        return $this;
362
    }
363
364
    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...
365
    {
366
        return $this->shareLink;
367
    }
368
369
    public function setShareLink($shareLink)
370
    {
371
        $this->shareLink = $shareLink;
372
373
        return $this;
374
    }
375
376
    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...
377
    {
378
        return $this->title;
379
    }
380
381
    public function setTitle($title)
382
    {
383
        $this->title = $title;
384
385
        return $this;
386
    }
387
388
    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...
389
    {
390
        return $this->commentCount;
391
    }
392
393
    public function setCommentCount($commentCount)
394
    {
395
        $this->commentCount = $commentCount;
396
397
        return $this;
398
    }
399
400
    public function getComments()
401
    {
402
        return $this->comments;
403
    }
404
405
    public function setComments(array $comments)
406
    {
407
        $this->comments = $comments;
408
409
        return $this;
410
    }
411
412
    public function getLastEditDate()
413
    {
414
        return $this->lastEditDate;
415
    }
416
417
    public function setLastEditDate(\DateTime $lastEditDate)
418
    {
419
        $this->lastEditDate = $lastEditDate;
420
421
        return $this;
422
    }
423
424
    public function getLastEditor()
425
    {
426
        return $this->lastEditor;
427
    }
428
429
    public function setLastEditor(ShallowUser $lastEditor)
430
    {
431
        $this->lastEditor = $lastEditor;
432
433
        return $this;
434
    }
435
436
    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...
437
    {
438
        return $this->downVoteCount;
439
    }
440
441
    public function setDownVoteCount($downVoteCount)
442
    {
443
        $this->downVoteCount = $downVoteCount;
444
445
        return $this;
446
    }
447
448
    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...
449
    {
450
        return $this->upVoteCount;
451
    }
452
453
    public function setUpVoteCount($upVoteCount)
454
    {
455
        $this->upVoteCount = $upVoteCount;
456
457
        return $this;
458
    }
459
460
    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...
461
    {
462
        return $this->body;
463
    }
464
465
    public function setBody($body)
466
    {
467
        $this->body = $body;
468
469
        return $this;
470
    }
471
472
    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...
473
    {
474
        return $this->bodyMarkDown;
475
    }
476
477
    public function setBodyMarkDown($bodyMarkDown)
478
    {
479
        $this->bodyMarkDown = $bodyMarkDown;
480
481
        return $this;
482
    }
483
484
    public function getCreationDate()
485
    {
486
        return $this->creationDate;
487
    }
488
489
    public function setCreationDate(\DateTime $creationDate)
490
    {
491
        $this->creationDate = $creationDate;
492
493
        return $this;
494
    }
495
496
    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...
497
    {
498
        return $this->link;
499
    }
500
501
    public function setLink($link)
502
    {
503
        $this->link = $link;
504
505
        return $this;
506
    }
507
508
    public function getOwner()
509
    {
510
        return $this->owner;
511
    }
512
513
    public function setOwner($owner)
514
    {
515
        $this->owner = $owner;
516
517
        return $this;
518
    }
519
520
    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...
521
    {
522
        return $this->score;
523
    }
524
525
    public function setScore($score)
526
    {
527
        $this->score = $score;
528
529
        return $this;
530
    }
531
532
    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...
533
    {
534
        return $this->upvoted;
535
    }
536
537
    public function setUpvoted($upvoted)
538
    {
539
        $this->upvoted = $upvoted;
540
541
        return $this;
542
    }
543
}
544