|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
/* |
|
14
|
|
|
* This file is part of the Stack Exchange Api Client library. |
|
15
|
|
|
* |
|
16
|
|
|
* (c) Beñat Espiña <[email protected]> |
|
17
|
|
|
* |
|
18
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
19
|
|
|
* file that was distributed with this source code. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace BenatEspina\StackExchangeApiClient\Model; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class question timeline model class. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Beñat Espiña <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class QuestionTimeline implements Model |
|
30
|
|
|
{ |
|
31
|
|
|
const TIMELINE_TYPES = [ |
|
32
|
|
|
'accepted_answer', |
|
33
|
|
|
'answer', |
|
34
|
|
|
'comment', |
|
35
|
|
|
'post_state_changed', |
|
36
|
|
|
'question', |
|
37
|
|
|
'revision', |
|
38
|
|
|
'unaccepted_answer', |
|
39
|
|
|
'vote_aggregate', |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
protected $downVoteCount; |
|
43
|
|
|
protected $upVoteCount; |
|
44
|
|
|
protected $commentId; |
|
45
|
|
|
protected $creationDate; |
|
46
|
|
|
protected $owner; |
|
47
|
|
|
protected $postId; |
|
48
|
|
|
protected $questionId; |
|
49
|
|
|
protected $revisionGuid; |
|
50
|
|
|
protected $timelineType; |
|
51
|
|
|
protected $user; |
|
52
|
|
|
|
|
53
|
|
|
public static function fromJson(array $data) |
|
54
|
|
|
{ |
|
55
|
|
|
$instance = new self(); |
|
56
|
|
|
$instance |
|
57
|
|
|
->setDownVoteCount(array_key_exists('down_vote_count', $data) ? $data['down_vote_count'] : null) |
|
58
|
|
|
->setUpVoteCount(array_key_exists('up_vote_count', $data) ? $data['up_vote_count'] : null) |
|
59
|
|
|
->setCommentId(array_key_exists('comment_id', $data) ? $data['comment_id'] : null) |
|
60
|
|
|
->setCreationDate( |
|
61
|
|
|
array_key_exists('creation_date', $data) |
|
62
|
|
|
? new \DateTimeImmutable('@' . $data['creation_date']) |
|
63
|
|
|
: null |
|
64
|
|
|
) |
|
65
|
|
|
->setOwner(array_key_exists('owner', $data) ? $data['owner'] : null) |
|
66
|
|
|
->setPostId(array_key_exists('post_id', $data) ? $data['post_id'] : null) |
|
67
|
|
|
->setQuestionId(array_key_exists('question_id', $data) ? $data['question_id'] : null) |
|
68
|
|
|
->setRevisionGuid(array_key_exists('revision_guid', $data) ? $data['revision_guid'] : null) |
|
69
|
|
|
->setTimelineType(array_key_exists('timeline_type', $data) ? $data['timeline_type'] : null) |
|
70
|
|
|
->setUser(array_key_exists('user', $data) ? $data['user'] : null); |
|
71
|
|
|
|
|
72
|
|
|
return $instance; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public static function fromProperties( |
|
76
|
|
|
$downVoteCount, |
|
77
|
|
|
$upVoteCount, |
|
78
|
|
|
$commentId, |
|
79
|
|
|
\DateTimeInterface $creationDate, |
|
80
|
|
|
ShallowUser $owner, |
|
81
|
|
|
$postId, |
|
82
|
|
|
$questionId, |
|
83
|
|
|
$revisionGuid, |
|
84
|
|
|
$timelineType, |
|
85
|
|
|
ShallowUser $user |
|
86
|
|
|
) { |
|
87
|
|
|
$instance = new self(); |
|
88
|
|
|
$instance |
|
89
|
|
|
->setDownVoteCount($downVoteCount) |
|
90
|
|
|
->setUpVoteCount($upVoteCount) |
|
91
|
|
|
->setCommentId($commentId) |
|
92
|
|
|
->setCreationDate($creationDate) |
|
93
|
|
|
->setOwner($owner) |
|
94
|
|
|
->setPostId($postId) |
|
95
|
|
|
->setQuestionId($questionId) |
|
96
|
|
|
->setRevisionGuid($revisionGuid) |
|
97
|
|
|
->setTimelineType($timelineType) |
|
98
|
|
|
->setUser($user); |
|
99
|
|
|
|
|
100
|
|
|
return $instance; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function setDownVoteCount($downVoteCount) |
|
104
|
|
|
{ |
|
105
|
|
|
$this->downVoteCount = $downVoteCount; |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function getDownVoteCount() |
|
|
|
|
|
|
111
|
|
|
{ |
|
112
|
|
|
return $this->downVoteCount; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
public function setUpVoteCount($upVoteCount) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->upVoteCount = $upVoteCount; |
|
118
|
|
|
|
|
119
|
|
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function getUpVoteCount() |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
return $this->upVoteCount; |
|
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) |
|
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 setOwner(ShallowUser $owner) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->owner = $owner; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function getOwner() |
|
159
|
|
|
{ |
|
160
|
|
|
return $this->owner; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function setPostId($postId) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->postId = $postId; |
|
166
|
|
|
|
|
167
|
|
|
return $this; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function getPostId() |
|
|
|
|
|
|
171
|
|
|
{ |
|
172
|
|
|
return $this->postId; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function setQuestionId($questionId) |
|
176
|
|
|
{ |
|
177
|
|
|
$this->questionId = $questionId; |
|
178
|
|
|
|
|
179
|
|
|
return $this; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function getQuestionId() |
|
|
|
|
|
|
183
|
|
|
{ |
|
184
|
|
|
return $this->questionId; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
public function setRevisionGuid($revisionGuid) |
|
188
|
|
|
{ |
|
189
|
|
|
$this->revisionGuid = $revisionGuid; |
|
190
|
|
|
|
|
191
|
|
|
return $this; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function getRevisionGuid() |
|
|
|
|
|
|
195
|
|
|
{ |
|
196
|
|
|
return $this->revisionGuid; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function setTimelineType($timelineType) |
|
200
|
|
|
{ |
|
201
|
|
|
if (in_array($timelineType, self::TIMELINE_TYPES, true)) { |
|
202
|
|
|
$this->timelineType = $timelineType; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function getTimelineType() |
|
|
|
|
|
|
209
|
|
|
{ |
|
210
|
|
|
return $this->timelineType; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function setUser(ShallowUser $user) |
|
214
|
|
|
{ |
|
215
|
|
|
$this->user = $user; |
|
216
|
|
|
|
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function getUser() |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->user; |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|
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
@returnannotation as described here.