@@ 23-111 (lines=89) @@ | ||
20 | * |
|
21 | * @author Beñat Espiña <[email protected]> |
|
22 | */ |
|
23 | class TagScore implements TagScoreInterface |
|
24 | { |
|
25 | /** |
|
26 | * Post count. |
|
27 | * |
|
28 | * @var int |
|
29 | */ |
|
30 | protected $postCount; |
|
31 | ||
32 | /** |
|
33 | * The score. |
|
34 | * |
|
35 | * @var int |
|
36 | */ |
|
37 | protected $score; |
|
38 | ||
39 | /** |
|
40 | * The user. |
|
41 | * |
|
42 | * @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface |
|
43 | */ |
|
44 | protected $user; |
|
45 | ||
46 | /** |
|
47 | * Constructor. |
|
48 | * |
|
49 | * @param null|mixed[] $json The json string being decoded |
|
50 | */ |
|
51 | public function __construct($json = null) |
|
52 | { |
|
53 | $this->postCount = Util::setIfIntegerExists($json, 'post_count'); |
|
54 | $this->score = Util::setIfIntegerExists($json, 'score'); |
|
55 | $this->user = new ShallowUser(Util::setIfArrayExists($json, 'user')); |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * {@inheritdoc} |
|
60 | */ |
|
61 | public function setPostCount($postCount) |
|
62 | { |
|
63 | $this->postCount = $postCount; |
|
64 | ||
65 | return $this; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * {@inheritdoc} |
|
70 | */ |
|
71 | public function getPostCount() |
|
72 | { |
|
73 | return $this->postCount; |
|
74 | } |
|
75 | ||
76 | /** |
|
77 | * {@inheritdoc} |
|
78 | */ |
|
79 | public function setScore($score) |
|
80 | { |
|
81 | $this->score = $score; |
|
82 | ||
83 | return $this; |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * {@inheritdoc} |
|
88 | */ |
|
89 | public function getScore() |
|
90 | { |
|
91 | return $this->score; |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * {@inheritdoc} |
|
96 | */ |
|
97 | public function setUser(ShallowUserInterface $user) |
|
98 | { |
|
99 | $this->user = $user; |
|
100 | ||
101 | return $this; |
|
102 | } |
|
103 | ||
104 | /** |
|
105 | * {@inheritdoc} |
|
106 | */ |
|
107 | public function getUser() |
|
108 | { |
|
109 | return $this->user; |
|
110 | } |
|
111 | } |
|
112 |
@@ 23-129 (lines=107) @@ | ||
20 | * |
|
21 | * @author Beñat Espiña <[email protected]> |
|
22 | */ |
|
23 | trait BountyTrait |
|
24 | { |
|
25 | /** |
|
26 | * The bounty amount. |
|
27 | * |
|
28 | * @var int|null |
|
29 | */ |
|
30 | protected $bodyAmount; |
|
31 | ||
32 | /** |
|
33 | * The bounty closes date. |
|
34 | * |
|
35 | * @var \DateTime|null |
|
36 | */ |
|
37 | protected $bountyClosesDate; |
|
38 | ||
39 | /** |
|
40 | * Bounty user. |
|
41 | * |
|
42 | * @var \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface|null |
|
43 | */ |
|
44 | protected $bountyUser; |
|
45 | ||
46 | /** |
|
47 | * Sets body amount. |
|
48 | * |
|
49 | * @param int|null $bodyAmount The body amount |
|
50 | * |
|
51 | * @return $this self Object |
|
52 | */ |
|
53 | public function setBodyAmount($bodyAmount) |
|
54 | { |
|
55 | $this->bodyAmount = $bodyAmount; |
|
56 | ||
57 | return $this; |
|
58 | } |
|
59 | ||
60 | /** |
|
61 | * Gets body amount. |
|
62 | * |
|
63 | * @return int|null |
|
64 | */ |
|
65 | public function getBodyAmount() |
|
66 | { |
|
67 | return $this->bodyAmount; |
|
68 | } |
|
69 | ||
70 | /** |
|
71 | * Sets bounty closes date. |
|
72 | * |
|
73 | * @param \DateTime|null $bountyClosesDate The bounty closes date |
|
74 | * |
|
75 | * @return $this self Object |
|
76 | */ |
|
77 | public function setBountyClosesDate(\DateTime $bountyClosesDate) |
|
78 | { |
|
79 | $this->bountyClosesDate = $bountyClosesDate; |
|
80 | ||
81 | return $this; |
|
82 | } |
|
83 | ||
84 | /** |
|
85 | * Gets bounty closes date. |
|
86 | * |
|
87 | * @return \DateTime|null |
|
88 | */ |
|
89 | public function getBountyClosesDate() |
|
90 | { |
|
91 | return $this->bountyClosesDate; |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * Sets bounty user. |
|
96 | * |
|
97 | * @param \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface|null $bountyUser The bounty user |
|
98 | * |
|
99 | * @return $this self Object |
|
100 | */ |
|
101 | public function setBountyUser(ShallowUserInterface $bountyUser) |
|
102 | { |
|
103 | $this->bountyUser = $bountyUser; |
|
104 | ||
105 | return $this; |
|
106 | } |
|
107 | ||
108 | /** |
|
109 | * Gets bounty user. |
|
110 | * |
|
111 | * @return \BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface|null |
|
112 | */ |
|
113 | public function getBountyUser() |
|
114 | { |
|
115 | return $this->bountyUser; |
|
116 | } |
|
117 | ||
118 | /** |
|
119 | * Loads the variables if the data exist into resource. It works like a constructor. |
|
120 | * |
|
121 | * @param null|mixed[] $resource The resource |
|
122 | */ |
|
123 | protected function loadBounty($resource) |
|
124 | { |
|
125 | $this->bodyAmount = Util::setIfIntegerExists($resource, 'body_amount'); |
|
126 | $this->bountyClosesDate = Util::setIfDateTimeExists($resource, 'bounty_closes_date'); |
|
127 | $this->bountyUser = new ShallowUser(Util::setIfArrayExists($resource, 'bounty_user')); |
|
128 | } |
|
129 | } |
|
130 |