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\Infrastructure\Domain\Model; |
13
|
|
|
|
14
|
|
|
use BenatEspina\StackExchangeApiClient\Domain\Model\BadgeCount; |
15
|
|
|
use BenatEspina\StackExchangeApiClient\Domain\Model\ShallowUser; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The anemic implementation of shallow user domain class. |
19
|
|
|
* |
20
|
|
|
* @author Beñat Espiña <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class AnemicShallowUser implements ShallowUser |
23
|
|
|
{ |
24
|
|
|
const USER_TYPE_DOES_NOT_EXIST = 'does_not_exist'; |
25
|
|
|
const USER_TYPE_MODERATOR = 'moderator'; |
26
|
|
|
const USER_TYPE_REGISTERED = 'registered'; |
27
|
|
|
const USER_TYPE_UNREGISTERED = 'unregistered'; |
28
|
|
|
|
29
|
|
|
private $id; |
30
|
|
|
private $acceptRate; |
31
|
|
|
private $badgeCounts; |
32
|
|
|
private $displayName; |
33
|
|
|
private $link; |
34
|
|
|
private $profileImage; |
35
|
|
|
private $reputation; |
36
|
|
|
private $userType; |
37
|
|
|
|
38
|
|
|
public static function fromJson($data) |
39
|
|
|
{ |
40
|
|
|
return new self( |
41
|
|
|
array_key_exists('user_id', $data) ? $data['user_id'] : null, |
42
|
|
|
array_key_exists('badge_counts', $data) ? AnemicBadgeCount::fromJson($data['badge_counts']) : null, |
43
|
|
|
array_key_exists('accept_rate', $data) ? $data['accept_rate'] : null, |
44
|
|
|
array_key_exists('display_name', $data) ? $data['display_name'] : null, |
45
|
|
|
array_key_exists('link', $data) ? $data['link'] : null, |
46
|
|
|
array_key_exists('profile_image', $data) ? $data['profile_image'] : null, |
47
|
|
|
array_key_exists('reputation', $data) ? $data['reputation'] : null, |
48
|
|
|
array_key_exists('user_type', $data) ? $data['user_type'] : null |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function fromProperties( |
53
|
|
|
$id, |
54
|
|
|
BadgeCount $badgeCounts, |
55
|
|
|
$userType, |
56
|
|
|
$acceptRate = null, |
57
|
|
|
$displayName = null, |
58
|
|
|
$link = null, |
59
|
|
|
$profileImage = null, |
60
|
|
|
$reputation = null |
61
|
|
|
) { |
62
|
|
|
return new self( |
63
|
|
|
$id, |
64
|
|
|
$acceptRate, |
65
|
|
|
$badgeCounts, |
66
|
|
|
$displayName, |
67
|
|
|
$link, |
68
|
|
|
$profileImage, |
69
|
|
|
$reputation, |
70
|
|
|
$userType |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
private function __construct( |
75
|
|
|
$id = null, |
76
|
|
|
BadgeCount $badgeCounts = null, |
77
|
|
|
$acceptRate = null, |
78
|
|
|
$displayName = null, |
79
|
|
|
$link = null, |
80
|
|
|
$profileImage = null, |
81
|
|
|
$reputation = null, |
82
|
|
|
$userType = null |
83
|
|
|
) { |
84
|
|
|
$this->id = $id; |
85
|
|
|
$this->acceptRate = $acceptRate; |
86
|
|
|
$this->badgeCounts = $badgeCounts; |
87
|
|
|
$this->displayName = $displayName; |
88
|
|
|
$this->link = $link; |
89
|
|
|
$this->profileImage = $profileImage; |
90
|
|
|
$this->reputation = $reputation; |
91
|
|
|
$this->setUserType($userType); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getId() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
return $this->id; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function setId($id) |
100
|
|
|
{ |
101
|
|
|
$this->id = $id; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function getAcceptRate() |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
return $this->acceptRate; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function setAcceptRate($acceptRate) |
112
|
|
|
{ |
113
|
|
|
$this->acceptRate = $acceptRate; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getBadgeCounts() |
119
|
|
|
{ |
120
|
|
|
return $this->badgeCounts; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setBadgeCounts($badgeCounts) |
124
|
|
|
{ |
125
|
|
|
$this->badgeCounts = $badgeCounts; |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getDisplayName() |
|
|
|
|
131
|
|
|
{ |
132
|
|
|
return $this->displayName; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function setDisplayName($displayName) |
136
|
|
|
{ |
137
|
|
|
$this->displayName = $displayName; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function getLink() |
|
|
|
|
143
|
|
|
{ |
144
|
|
|
return $this->link; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function setLink($link) |
148
|
|
|
{ |
149
|
|
|
$this->link = $link; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function getProfileImage() |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
return $this->profileImage; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function setProfileImage($profileImage) |
160
|
|
|
{ |
161
|
|
|
$this->profileImage = $profileImage; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function getReputation() |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
return $this->reputation; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function setReputation($reputation) |
172
|
|
|
{ |
173
|
|
|
$this->reputation = $reputation; |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function getUserType() |
|
|
|
|
179
|
|
|
{ |
180
|
|
|
return $this->userType; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
View Code Duplication |
public function setUserType($userType) |
|
|
|
|
184
|
|
|
{ |
185
|
|
|
if (in_array($userType, [ |
186
|
|
|
self::USER_TYPE_DOES_NOT_EXIST, |
187
|
|
|
self::USER_TYPE_MODERATOR, |
188
|
|
|
self::USER_TYPE_REGISTERED, |
189
|
|
|
self::USER_TYPE_UNREGISTERED, |
190
|
|
|
], true)) { |
191
|
|
|
$this->userType = $userType; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
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.