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 question timeline model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class QuestionTimeline implements Model |
20
|
|
|
{ |
21
|
|
|
const TIMELINE_TYPES = [ |
22
|
|
|
'accepted_answer', |
23
|
|
|
'answer', |
24
|
|
|
'comment', |
25
|
|
|
'post_state_changed', |
26
|
|
|
'question', |
27
|
|
|
'revision', |
28
|
|
|
'unaccepted_answer', |
29
|
|
|
'vote_aggregate', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
protected $downVoteCount; |
33
|
|
|
protected $upVoteCount; |
34
|
|
|
protected $commentId; |
35
|
|
|
protected $creationDate; |
36
|
|
|
protected $owner; |
37
|
|
|
protected $postId; |
38
|
|
|
protected $questionId; |
39
|
|
|
protected $revisionGuid; |
40
|
|
|
protected $timelineType; |
41
|
|
|
protected $user; |
42
|
|
|
|
43
|
|
|
public static function fromJson(array $data) |
44
|
|
|
{ |
45
|
|
|
$instance = new self(); |
46
|
|
|
$instance |
47
|
|
|
->setDownVoteCount(array_key_exists('down_vote_count', $data) ? $data['down_vote_count'] : null) |
48
|
|
|
->setUpVoteCount(array_key_exists('up_vote_count', $data) ? $data['up_vote_count'] : null) |
49
|
|
|
->setCommentId(array_key_exists('comment_id', $data) ? $data['comment_id'] : null) |
50
|
|
|
->setCreationDate( |
51
|
|
|
array_key_exists('creation_date', $data) |
|
|
|
|
52
|
|
|
? new \DateTimeImmutable('@' . $data['creation_date']) |
53
|
|
|
: null |
54
|
|
|
) |
55
|
|
|
->setOwner(array_key_exists('owner', $data) ? $data['owner'] : null) |
56
|
|
|
->setPostId(array_key_exists('post_id', $data) ? $data['post_id'] : null) |
57
|
|
|
->setQuestionId(array_key_exists('question_id', $data) ? $data['question_id'] : null) |
58
|
|
|
->setRevisionGuid(array_key_exists('revision_guid', $data) ? $data['revision_guid'] : null) |
59
|
|
|
->setTimelineType(array_key_exists('timeline_type', $data) ? $data['timeline_type'] : null) |
60
|
|
|
->setUser(array_key_exists('user', $data) ? $data['user'] : null); |
61
|
|
|
|
62
|
|
|
return $instance; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function fromProperties( |
66
|
|
|
$downVoteCount, |
67
|
|
|
$upVoteCount, |
68
|
|
|
$commentId, |
69
|
|
|
\DateTimeInterface $creationDate, |
70
|
|
|
ShallowUser $owner, |
71
|
|
|
$postId, |
72
|
|
|
$questionId, |
73
|
|
|
$revisionGuid, |
74
|
|
|
$timelineType, |
75
|
|
|
ShallowUser $user |
76
|
|
|
) { |
77
|
|
|
$instance = new self(); |
78
|
|
|
$instance |
79
|
|
|
->setDownVoteCount($downVoteCount) |
80
|
|
|
->setUpVoteCount($upVoteCount) |
81
|
|
|
->setCommentId($commentId) |
82
|
|
|
->setCreationDate($creationDate) |
83
|
|
|
->setOwner($owner) |
84
|
|
|
->setPostId($postId) |
85
|
|
|
->setQuestionId($questionId) |
86
|
|
|
->setRevisionGuid($revisionGuid) |
87
|
|
|
->setTimelineType($timelineType) |
88
|
|
|
->setUser($user); |
89
|
|
|
|
90
|
|
|
return $instance; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setDownVoteCount($downVoteCount) |
94
|
|
|
{ |
95
|
|
|
$this->downVoteCount = $downVoteCount; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getDownVoteCount() |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
return $this->downVoteCount; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setUpVoteCount($upVoteCount) |
106
|
|
|
{ |
107
|
|
|
$this->upVoteCount = $upVoteCount; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getUpVoteCount() |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
return $this->upVoteCount; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function setCommentId($commentId) |
118
|
|
|
{ |
119
|
|
|
$this->commentId = $commentId; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getCommentId() |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
return $this->commentId; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function setCreationDate(\DateTimeInterface $creationDate) |
130
|
|
|
{ |
131
|
|
|
$this->creationDate = $creationDate; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getCreationDate() |
137
|
|
|
{ |
138
|
|
|
return $this->creationDate; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function setOwner(ShallowUser $owner) |
142
|
|
|
{ |
143
|
|
|
$this->owner = $owner; |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getOwner() |
149
|
|
|
{ |
150
|
|
|
return $this->owner; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setPostId($postId) |
154
|
|
|
{ |
155
|
|
|
$this->postId = $postId; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function getPostId() |
|
|
|
|
161
|
|
|
{ |
162
|
|
|
return $this->postId; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function setQuestionId($questionId) |
166
|
|
|
{ |
167
|
|
|
$this->questionId = $questionId; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function getQuestionId() |
|
|
|
|
173
|
|
|
{ |
174
|
|
|
return $this->questionId; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function setRevisionGuid($revisionGuid) |
178
|
|
|
{ |
179
|
|
|
$this->revisionGuid = $revisionGuid; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function getRevisionGuid() |
|
|
|
|
185
|
|
|
{ |
186
|
|
|
return $this->revisionGuid; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function setTimelineType($timelineType) |
190
|
|
|
{ |
191
|
|
|
if (in_array($timelineType, self::TIMELINE_TYPES, true)) { |
192
|
|
|
$this->timelineType = $timelineType; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getTimelineType() |
|
|
|
|
199
|
|
|
{ |
200
|
|
|
return $this->timelineType; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function setUser(ShallowUser $user) |
204
|
|
|
{ |
205
|
|
|
$this->user = $user; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function getUser() |
211
|
|
|
{ |
212
|
|
|
return $this->user; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: