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
|
|
|
* Class inbox item model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class InboxItem implements Model |
20
|
|
|
{ |
21
|
|
|
const ITEM_TYPES = [ |
22
|
|
|
'careers_invitations', |
23
|
|
|
'careers_message', |
24
|
|
|
'chat_message', 'comment', |
25
|
|
|
'meta_question', |
26
|
|
|
'moderator_message', |
27
|
|
|
'new_answer', |
28
|
|
|
'post_notice', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
protected $answerId; |
32
|
|
|
protected $body; |
33
|
|
|
protected $questionId; |
34
|
|
|
protected $commentId; |
35
|
|
|
protected $creationDate; |
36
|
|
|
protected $isUnread; |
37
|
|
|
protected $itemType; |
38
|
|
|
protected $link; |
39
|
|
|
protected $site; |
40
|
|
|
protected $title; |
41
|
|
|
|
42
|
|
|
public static function fromJson(array $data) |
43
|
|
|
{ |
44
|
|
|
$instance = new self(); |
45
|
|
|
$instance |
46
|
|
|
->setAnswerId(array_key_exists('answer_id', $data) ? $data['answer_id'] : null) |
47
|
|
|
->setBody(array_key_exists('body', $data) ? $data['body'] : null) |
48
|
|
|
->setCommentId(array_key_exists('comment_id', $data) ? $data['comment_id'] : null) |
49
|
|
|
->setCreationDate(array_key_exists('creation_date', $data) |
50
|
|
|
? new \DateTimeImmutable('@' . $data['creation_date']) |
51
|
|
|
: null |
52
|
|
|
) |
53
|
|
|
->setUnread(array_key_exists('is_unread', $data) ? $data['is_unread'] : null) |
54
|
|
|
->setItemType(array_key_exists('item_type', $data) ? $data['item_type'] : null) |
55
|
|
|
->setLink(array_key_exists('link', $data) ? $data['link'] : null) |
56
|
|
|
->setQuestionId(array_key_exists('question_id', $data) ? $data['question_id'] : null) |
57
|
|
|
->setSite(array_key_exists('site', $data) ? Site::fromJson($data['site']) : null) |
|
|
|
|
58
|
|
|
->setTitle(array_key_exists('title', $data) ? $data['title'] : null); |
59
|
|
|
|
60
|
|
|
return $instance; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public static function fromProperties( |
64
|
|
|
$answerId, |
65
|
|
|
$commentId, |
66
|
|
|
\DateTimeInterface $creationDate, |
67
|
|
|
$isUnread, |
68
|
|
|
$itemType, |
69
|
|
|
$link, |
70
|
|
|
$questionId, |
71
|
|
|
Site $site, |
72
|
|
|
$title, |
73
|
|
|
$body = null |
74
|
|
|
) { |
75
|
|
|
$instance = new self(); |
76
|
|
|
$instance |
77
|
|
|
->setAnswerId($answerId) |
78
|
|
|
->setBody($body) |
79
|
|
|
->setCommentId($commentId) |
80
|
|
|
->setCreationDate($creationDate) |
81
|
|
|
->setUnread($isUnread) |
82
|
|
|
->setItemType($itemType) |
83
|
|
|
->setLink($link) |
84
|
|
|
->setQuestionId($questionId) |
85
|
|
|
->setSite($site) |
86
|
|
|
->setTitle($title); |
87
|
|
|
|
88
|
|
|
return $instance; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function setAnswerId($answerId) |
92
|
|
|
{ |
93
|
|
|
$this->answerId = $answerId; |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getAnswerId() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
return $this->answerId; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function setBody($body) |
104
|
|
|
{ |
105
|
|
|
$this->body = $body; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getBody() |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
return $this->body; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function setQuestionId($questionId) |
116
|
|
|
{ |
117
|
|
|
$this->questionId = $questionId; |
118
|
|
|
|
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getQuestionId() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
return $this->questionId; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function setCommentId($commentId) |
128
|
|
|
{ |
129
|
|
|
$this->commentId = $commentId; |
130
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getCommentId() |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
return $this->commentId; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setCreationDate(\DateTimeInterface $creationDate = null) |
140
|
|
|
{ |
141
|
|
|
$this->creationDate = $creationDate; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function getCreationDate() |
147
|
|
|
{ |
148
|
|
|
return $this->creationDate; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function setUnread($isUnread) |
152
|
|
|
{ |
153
|
|
|
$this->isUnread = $isUnread; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function isUnread() |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
return $this->isUnread; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setItemType($itemType) |
164
|
|
|
{ |
165
|
|
|
if (in_array($itemType, self::ITEM_TYPES, true)) { |
166
|
|
|
$this->itemType = $itemType; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function getItemType() |
|
|
|
|
173
|
|
|
{ |
174
|
|
|
return $this->itemType; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function setLink($link) |
178
|
|
|
{ |
179
|
|
|
$this->link = $link; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function getLink() |
|
|
|
|
185
|
|
|
{ |
186
|
|
|
return $this->link; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function setSite(Site $site = null) |
190
|
|
|
{ |
191
|
|
|
$this->site = $site; |
192
|
|
|
|
193
|
|
|
return $this; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function getSite() |
197
|
|
|
{ |
198
|
|
|
return $this->site; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function setTitle($title) |
202
|
|
|
{ |
203
|
|
|
$this->title = $title; |
204
|
|
|
|
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function getTitle() |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
return $this->title; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
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.