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\Comment; |
15
|
|
|
use BenatEspina\StackExchangeApiClient\Domain\Model\ShallowUser; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The anemic implementation of comment domain class. |
19
|
|
|
* |
20
|
|
|
* @author Beñat Espiña <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class AnemicComment implements Comment |
23
|
|
|
{ |
24
|
|
|
const POST_TYPE_QUESTION = 'question'; |
25
|
|
|
const POST_TYPE_ANSWER = 'answer'; |
26
|
|
|
|
27
|
|
|
private $id; |
28
|
|
|
private $body; |
29
|
|
|
private $bodyMarkdown; |
30
|
|
|
private $canFlag; |
31
|
|
|
private $creationDate; |
32
|
|
|
private $edited; |
33
|
|
|
private $link; |
34
|
|
|
private $owner; |
35
|
|
|
private $postId; |
36
|
|
|
private $postType; |
37
|
|
|
private $replyToUser; |
38
|
|
|
private $score; |
39
|
|
|
private $upvoted; |
40
|
|
|
|
41
|
|
|
public static function fromProperties( |
42
|
|
|
$id, |
43
|
|
|
$body, |
44
|
|
|
$bodyMarkdown, |
45
|
|
|
$canFlag, |
46
|
|
|
\DateTimeInterface $creationDate, |
47
|
|
|
$edited, |
48
|
|
|
$link, |
49
|
|
|
$postId, |
50
|
|
|
$postType, |
51
|
|
|
$score, |
52
|
|
|
$upvoted, |
53
|
|
|
ShallowUser $owner = null, |
54
|
|
|
ShallowUser $replyToUser = null |
55
|
|
|
) { |
56
|
|
|
return new self( |
57
|
|
|
$id, |
58
|
|
|
$body, |
59
|
|
|
$bodyMarkdown, |
60
|
|
|
$canFlag, |
61
|
|
|
$creationDate, |
62
|
|
|
$edited, |
63
|
|
|
$link, |
64
|
|
|
$owner, |
65
|
|
|
$postId, |
66
|
|
|
$postType, |
67
|
|
|
$replyToUser, |
68
|
|
|
$score, |
69
|
|
|
$upvoted |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public static function fromJson($data) |
74
|
|
|
{ |
75
|
|
|
return new self( |
76
|
|
|
array_key_exists('comment_id', $data) ? $data['comment_id'] : null, |
77
|
|
|
array_key_exists('body', $data) ? $data['body'] : null, |
78
|
|
|
array_key_exists('body_markdown', $data) ? $data['body_markdown'] : null, |
79
|
|
|
array_key_exists('can_flag', $data) ? $data['can_flag'] : null, |
80
|
|
|
array_key_exists('creation_date', $data) ? new \DateTimeImmutable('@' . $data['creation_date']) : null, |
81
|
|
|
array_key_exists('edited', $data) ? $data['edited'] : null, |
82
|
|
|
array_key_exists('link', $data) ? $data['link'] : null, |
83
|
|
|
array_key_exists('owner', $data) ? AnemicShallowUser::fromJson($data['owner']) : null, |
84
|
|
|
array_key_exists('postId', $data) ? $data['postId'] : null, |
85
|
|
|
array_key_exists('post_type', $data) ? $data['post_type'] : null, |
86
|
|
|
array_key_exists('reply_to_user', $data) ? AnemicShallowUser::fromJson($data['reply_to_user']) : null, |
87
|
|
|
array_key_exists('score', $data) ? $data['score'] : null, |
88
|
|
|
array_key_exists('upvoted', $data) ? $data['upvoted'] : null |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function __construct( |
93
|
|
|
$id = null, |
94
|
|
|
$body = null, |
95
|
|
|
$bodyMarkdown = null, |
96
|
|
|
$canFlag = null, |
97
|
|
|
\DateTimeInterface $creationDate = null, |
98
|
|
|
$edited = null, |
99
|
|
|
$link = null, |
100
|
|
|
ShallowUser $owner = null, |
101
|
|
|
$postId = null, |
102
|
|
|
$postType = null, |
103
|
|
|
ShallowUser $replyToUser = null, |
104
|
|
|
$score = null, |
105
|
|
|
$upvoted = null |
106
|
|
|
) { |
107
|
|
|
$this->id = $id; |
108
|
|
|
$this->body = $body; |
109
|
|
|
$this->bodyMarkdown = $bodyMarkdown; |
110
|
|
|
$this->canFlag = $canFlag; |
111
|
|
|
$this->creationDate = $creationDate; |
112
|
|
|
$this->edited = $edited; |
113
|
|
|
$this->link = $link; |
114
|
|
|
$this->owner = $owner; |
115
|
|
|
$this->postId = $postId; |
116
|
|
|
$this->setPostType($postType); |
117
|
|
|
$this->replyToUser = $replyToUser; |
118
|
|
|
$this->score = $score; |
119
|
|
|
$this->upvoted = $upvoted; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function getId() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
return $this->id; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function setId($id) |
128
|
|
|
{ |
129
|
|
|
$this->id = $id; |
130
|
|
|
|
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getBody() |
|
|
|
|
135
|
|
|
{ |
136
|
|
|
return $this->body; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function setBody($body) |
140
|
|
|
{ |
141
|
|
|
$this->body = $body; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function getBodyMarkdown() |
|
|
|
|
147
|
|
|
{ |
148
|
|
|
return $this->bodyMarkdown; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function setBodyMarkdown($bodyMarkdown) |
152
|
|
|
{ |
153
|
|
|
$this->bodyMarkdown = $bodyMarkdown; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getCanFlag() |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
return $this->canFlag; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setCanFlag($canFlag) |
164
|
|
|
{ |
165
|
|
|
$this->canFlag = $canFlag; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function getCreationDate() |
171
|
|
|
{ |
172
|
|
|
return $this->creationDate; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function setCreationDate(\DateTimeInterface $creationDate) |
176
|
|
|
{ |
177
|
|
|
$this->creationDate = $creationDate; |
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function getEdited() |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
return $this->edited; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function setEdited($edited) |
188
|
|
|
{ |
189
|
|
|
$this->edited = $edited; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function getLink() |
|
|
|
|
195
|
|
|
{ |
196
|
|
|
return $this->link; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function setLink($link) |
200
|
|
|
{ |
201
|
|
|
$this->link = $link; |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function getOwner() |
207
|
|
|
{ |
208
|
|
|
return $this->owner; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function setOwner(ShallowUser $owner) |
212
|
|
|
{ |
213
|
|
|
$this->owner = $owner; |
214
|
|
|
|
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function getPostId() |
|
|
|
|
219
|
|
|
{ |
220
|
|
|
return $this->postId; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function setPostId($postId) |
224
|
|
|
{ |
225
|
|
|
$this->postId = $postId; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function getPostType() |
|
|
|
|
231
|
|
|
{ |
232
|
|
|
return $this->postType; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
View Code Duplication |
public function setPostType($postType) |
|
|
|
|
236
|
|
|
{ |
237
|
|
|
if (in_array($postType, [self::POST_TYPE_QUESTION, self::POST_TYPE_ANSWER], true)) { |
238
|
|
|
$this->postType = $postType; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function getReplyToUser() |
245
|
|
|
{ |
246
|
|
|
return $this->replyToUser; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function setReplyToUser(ShallowUser $replyToUser) |
250
|
|
|
{ |
251
|
|
|
$this->replyToUser = $replyToUser; |
252
|
|
|
|
253
|
|
|
return $this; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function getScore() |
|
|
|
|
257
|
|
|
{ |
258
|
|
|
return $this->score; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
public function setScore($score) |
262
|
|
|
{ |
263
|
|
|
$this->score = $score; |
264
|
|
|
|
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function getUpvoted() |
|
|
|
|
269
|
|
|
{ |
270
|
|
|
return $this->upvoted; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function setUpvoted($upvoted) |
274
|
|
|
{ |
275
|
|
|
$this->upvoted = $upvoted; |
276
|
|
|
|
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
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.