1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 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\Traits; |
13
|
|
|
|
14
|
|
|
use BenatEspina\StackExchangeApiClient\Model\Interfaces\ShallowUserInterface; |
15
|
|
|
use BenatEspina\StackExchangeApiClient\Model\ShallowUser; |
16
|
|
|
use BenatEspina\StackExchangeApiClient\Util\Util; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Trait BountyTrait. |
20
|
|
|
* |
21
|
|
|
* @author Beñat Espiña <[email protected]> |
22
|
|
|
*/ |
23
|
|
View Code Duplication |
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.