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\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The notice model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Notice implements Model |
20
|
|
|
{ |
21
|
|
|
protected $body; |
22
|
|
|
protected $creationDate; |
23
|
|
|
protected $ownerUserId; |
24
|
|
|
|
25
|
|
View Code Duplication |
public static function fromJson(array $data) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$instance = new self(); |
28
|
|
|
$instance |
29
|
|
|
->setBody(array_key_exists('body', $data) ? $data['body'] : null) |
30
|
|
|
->setCreationDate(array_key_exists('creation_date', $data) |
31
|
|
|
? new \DateTimeImmutable('@' . $data['creation_date']) |
32
|
|
|
: null |
33
|
|
|
) |
34
|
|
|
->setOwnerUserId(array_key_exists('owner_user_id', $data) ? $data['owner_user_id'] : null); |
35
|
|
|
|
36
|
|
|
return $instance; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public static function fromProperties($body, \DateTimeInterface $creationDate, $ownerUserId) |
40
|
|
|
{ |
41
|
|
|
$instance = new self(); |
42
|
|
|
|
43
|
|
|
$instance |
44
|
|
|
->setBody($body) |
45
|
|
|
->setCreationDate($creationDate) |
46
|
|
|
->setOwnerUserId($ownerUserId); |
47
|
|
|
|
48
|
|
|
return $instance; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function setBody($body) |
53
|
|
|
{ |
54
|
|
|
$this->body = $body; |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getBody() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
return $this->body; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setCreationDate(\DateTimeInterface $creationDate = null) |
65
|
|
|
{ |
66
|
|
|
$this->creationDate = $creationDate; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getCreationDate() |
72
|
|
|
{ |
73
|
|
|
return $this->creationDate; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setOwnerUserId($ownerUserId) |
77
|
|
|
{ |
78
|
|
|
$this->ownerUserId = $ownerUserId; |
79
|
|
|
|
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getOwnerUserId() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
return $this->ownerUserId; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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.