|
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 notification model class. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Beñat Espiña <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class Notification implements Model |
|
20
|
|
|
{ |
|
21
|
|
|
const NOTIFICATION_TYPES = [ |
|
22
|
|
|
'accounts_associated', |
|
23
|
|
|
'badge_earned', |
|
24
|
|
|
'bounty_expired', |
|
25
|
|
|
'bounty_expires_in_one_day', |
|
26
|
|
|
'bounty_expires_in_three_days', |
|
27
|
|
|
'bounty_period_started', |
|
28
|
|
|
'edit_suggested', |
|
29
|
|
|
'generic', |
|
30
|
|
|
'moderator_message', |
|
31
|
|
|
'new_privileges', |
|
32
|
|
|
'post_migrated', |
|
33
|
|
|
'profile_activity', |
|
34
|
|
|
'registration_reminder', |
|
35
|
|
|
'reputation_bonus', |
|
36
|
|
|
'substantive_edit', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
protected $body; |
|
40
|
|
|
protected $creationDate; |
|
41
|
|
|
protected $isUnread; |
|
42
|
|
|
protected $notificationType; |
|
43
|
|
|
protected $postId; |
|
44
|
|
|
protected $site; |
|
45
|
|
|
|
|
46
|
|
|
public static function fromProperties( |
|
47
|
|
|
$body, |
|
48
|
|
|
$creationDate, |
|
49
|
|
|
$isUnread, |
|
50
|
|
|
$notificationType, |
|
51
|
|
|
$postId, |
|
52
|
|
|
Site $site |
|
53
|
|
|
) { |
|
54
|
|
|
$instance = new self(); |
|
55
|
|
|
$instance |
|
56
|
|
|
->setBody($body) |
|
57
|
|
|
->setCreationDate($creationDate) |
|
58
|
|
|
->setUnread($isUnread) |
|
59
|
|
|
->setNotificationType($notificationType) |
|
60
|
|
|
->setPostId($postId) |
|
61
|
|
|
->setSite($site); |
|
62
|
|
|
|
|
63
|
|
|
return $instance; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public static function fromJson(array $data) |
|
67
|
|
|
{ |
|
68
|
|
|
$instance = new self(); |
|
69
|
|
|
$instance |
|
70
|
|
|
->setBody(array_key_exists('body', $data) ? $data['body'] : null) |
|
71
|
|
|
->setCreationDate( |
|
72
|
|
|
array_key_exists('creation_date', $data) |
|
73
|
|
|
? new \DateTimeImmutable('@' . $data['creation_date']) |
|
74
|
|
|
: null |
|
75
|
|
|
) |
|
76
|
|
|
->setUnread(array_key_exists('is_unread', $data) ? $data['is_unread'] : null) |
|
77
|
|
|
->setNotificationType(array_key_exists('notification_type', $data) ? $data['notification_type'] : null) |
|
78
|
|
|
->setPostId(array_key_exists('post_id', $data) ? $data['post_id'] : null) |
|
79
|
|
|
->setSite(array_key_exists('site', $data) ? Site::fromJson($data['site']) : null); |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
return $instance; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function setBody($body) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->body = $body; |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getBody() |
|
|
|
|
|
|
92
|
|
|
{ |
|
93
|
|
|
return $this->body; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function setCreationDate(\DateTimeInterface $creationDate = null) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->creationDate = $creationDate; |
|
99
|
|
|
|
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getCreationDate() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->creationDate; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function setUnread($isUnread) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->isUnread = $isUnread; |
|
111
|
|
|
|
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function isUnread() |
|
|
|
|
|
|
116
|
|
|
{ |
|
117
|
|
|
return $this->isUnread; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function setNotificationType($notificationType) |
|
121
|
|
|
{ |
|
122
|
|
|
if (in_array($notificationType, self::NOTIFICATION_TYPES, true)) { |
|
123
|
|
|
$this->notificationType = $notificationType; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function getNotificationType() |
|
|
|
|
|
|
130
|
|
|
{ |
|
131
|
|
|
return $this->notificationType; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function setPostId($postId) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->postId = $postId; |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getPostId() |
|
|
|
|
|
|
142
|
|
|
{ |
|
143
|
|
|
return $this->postId; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function setSite(Site $site = null) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->site = $site; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function getSite() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->site; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.