1 | <?php |
||
19 | class NetworkPost implements Model |
||
20 | { |
||
21 | const POST_TYPES = ['question', 'answer']; |
||
22 | |||
23 | protected $id; |
||
24 | protected $postType; |
||
25 | protected $score; |
||
26 | protected $title; |
||
27 | |||
28 | public static function fromProperties($id, $postType, $score, $title) |
||
29 | { |
||
30 | $instance = new self(); |
||
31 | $instance |
||
32 | ->setId($id) |
||
33 | ->setPostType($postType) |
||
34 | ->setScore($score) |
||
35 | ->setTitle($title); |
||
36 | |||
37 | return $instance; |
||
38 | } |
||
39 | |||
40 | public static function fromJson(array $data) |
||
41 | { |
||
42 | $instance = new self(); |
||
43 | $instance |
||
44 | ->setId(array_key_exists('post_id', $data) ? $data['post_id'] : null) |
||
45 | ->setPostType(array_key_exists('post_type', $data) ? $data['post_type'] : null) |
||
46 | ->setScore(array_key_exists('score', $data) ? $data['score'] : null) |
||
47 | ->setTitle(array_key_exists('title', $data) ? $data['title'] : null); |
||
48 | |||
49 | return $instance; |
||
50 | } |
||
51 | |||
52 | public function getId() |
||
56 | |||
57 | public function setId($id) |
||
58 | { |
||
59 | $this->id = $id; |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | public function getPostType() |
||
68 | |||
69 | public function setPostType($postType) |
||
70 | { |
||
71 | if (in_array($postType, self::POST_TYPES, true)) { |
||
72 | $this->postType = $postType; |
||
73 | } |
||
74 | |||
75 | return $this; |
||
76 | } |
||
77 | |||
78 | public function getScore() |
||
82 | |||
83 | public function setScore($score) |
||
84 | { |
||
85 | $this->score = $score; |
||
86 | |||
87 | return $this; |
||
88 | } |
||
89 | |||
90 | public function getTitle() |
||
94 | |||
95 | public function setTitle($title) |
||
96 | { |
||
97 | $this->title = $title; |
||
98 | |||
99 | return $this; |
||
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.