1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2015 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 network post model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class NetworkPost |
20
|
|
|
{ |
21
|
|
|
const POST_TYPE_QUESTION = 'question'; |
22
|
|
|
const POST_TYPE_ANSWER = 'answer'; |
23
|
|
|
|
24
|
|
|
private $id; |
25
|
|
|
private $postType; |
26
|
|
|
private $score; |
27
|
|
|
private $title; |
28
|
|
|
|
29
|
|
|
public static function fromProperties($id, $postType, $score, $title) |
30
|
|
|
{ |
31
|
|
|
return new self($id, $postType, $score, $title); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function fromJson(array $data) |
35
|
|
|
{ |
36
|
|
|
return new self( |
37
|
|
|
array_key_exists('post_id', $data) ? $data['post_id'] : null, |
38
|
|
|
array_key_exists('post_type', $data) ? $data['post_type'] : null, |
39
|
|
|
array_key_exists('score', $data) ? $data['score'] : null, |
40
|
|
|
array_key_exists('title', $data) ? $data['title'] : null |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function __construct($id = null, $postType = null, $score = null, $title = null) |
45
|
|
|
{ |
46
|
|
|
$this->id = $id; |
47
|
|
|
$this->setPostType($postType); |
48
|
|
|
$this->score = $score; |
49
|
|
|
$this->title = $title; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getId() |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
return $this->id; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function setId($id) |
58
|
|
|
{ |
59
|
|
|
$this->id = $id; |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getPostType() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
return $this->postType; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public function setPostType($postType) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
if (in_array($postType, [self::POST_TYPE_QUESTION, self::POST_TYPE_ANSWER])) { |
72
|
|
|
$this->postType = $postType; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getScore() |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
return $this->score; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setScore($score) |
84
|
|
|
{ |
85
|
|
|
$this->score = $score; |
86
|
|
|
|
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getTitle() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
return $this->title; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function setTitle($title) |
96
|
|
|
{ |
97
|
|
|
$this->title = $title; |
98
|
|
|
|
99
|
|
|
return $this; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.