1 | <?php |
||
51 | class FederatedUser extends ManagedModel implements |
||
52 | IFederatedUser, |
||
53 | IMemberships, |
||
54 | IDeserializable, |
||
55 | INC22QueryRow, |
||
56 | JsonSerializable { |
||
57 | |||
58 | |||
59 | use TArrayTools; |
||
60 | use TNC22Deserialize; |
||
61 | |||
62 | |||
63 | /** @var string */ |
||
64 | private $singleId = ''; |
||
65 | |||
66 | /** @var string */ |
||
67 | private $userId; |
||
68 | |||
69 | /** @var int */ |
||
70 | private $userType; |
||
71 | |||
72 | /** @var Circle */ |
||
73 | private $basedOn; |
||
74 | |||
75 | /** @var int */ |
||
76 | private $config = 0; |
||
77 | |||
78 | /** @var string */ |
||
79 | private $instance; |
||
80 | |||
81 | /** @var Membership */ |
||
82 | private $link; |
||
83 | |||
84 | /** @var Membership[] */ |
||
85 | private $memberships = null; |
||
86 | |||
87 | |||
88 | /** |
||
89 | * FederatedUser constructor. |
||
90 | */ |
||
91 | public function __construct() { |
||
93 | |||
94 | |||
95 | /** |
||
96 | * @param string $userId |
||
97 | * @param string $instance |
||
98 | * @param int $type |
||
99 | * @param Circle|null $basedOn |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | public function set( |
||
117 | |||
118 | |||
119 | /** |
||
120 | * @param string $singleId |
||
121 | * |
||
122 | * @return self |
||
123 | */ |
||
124 | public function setSingleId(string $singleId): self { |
||
129 | |||
130 | /** |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getSingleId(): string { |
||
136 | |||
137 | |||
138 | /** |
||
139 | * @param string $userId |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | public function setUserId(string $userId): self { |
||
148 | |||
149 | /** |
||
150 | * @return string |
||
151 | */ |
||
152 | public function getUserId(): string { |
||
155 | |||
156 | |||
157 | /** |
||
158 | * @param int $userType |
||
159 | * |
||
160 | * @return self |
||
161 | */ |
||
162 | public function setUserType(int $userType): self { |
||
167 | |||
168 | |||
169 | /** |
||
170 | * @return int |
||
171 | */ |
||
172 | public function getUserType(): int { |
||
175 | |||
176 | |||
177 | /** |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function hasBasedOn(): bool { |
||
183 | |||
184 | /** |
||
185 | * @param Circle|null $basedOn |
||
186 | * |
||
187 | * @return $this |
||
188 | */ |
||
189 | public function setBasedOn(?Circle $basedOn): self { |
||
194 | |||
195 | /** |
||
196 | * @return Circle |
||
197 | */ |
||
198 | public function getBasedOn(): Circle { |
||
201 | |||
202 | |||
203 | /** |
||
204 | * @param int $config |
||
205 | * |
||
206 | * @return self |
||
207 | */ |
||
208 | public function setConfig(int $config): self { |
||
213 | |||
214 | /** |
||
215 | * @return int |
||
216 | */ |
||
217 | public function getConfig(): int { |
||
220 | |||
221 | |||
222 | /** |
||
223 | * @param string $instance |
||
224 | * |
||
225 | * @return self |
||
226 | */ |
||
227 | public function setInstance(string $instance): self { |
||
236 | |||
237 | /** |
||
238 | * @return string |
||
239 | */ |
||
240 | public function getInstance(): string { |
||
243 | |||
244 | |||
245 | /** |
||
246 | * @return bool |
||
247 | */ |
||
248 | public function hasMemberships(): bool { |
||
251 | |||
252 | /** |
||
253 | * @param array $memberships |
||
254 | * |
||
255 | * @return self |
||
256 | */ |
||
257 | public function setMemberships(array $memberships): IMemberships { |
||
262 | |||
263 | /** |
||
264 | * @return Membership[] |
||
265 | */ |
||
266 | public function getMemberships(): array { |
||
273 | |||
274 | |||
275 | /** |
||
276 | * @return bool |
||
277 | */ |
||
278 | public function hasLink(): bool { |
||
281 | |||
282 | /** |
||
283 | * @param Membership $link |
||
284 | * |
||
285 | * @return $this |
||
286 | */ |
||
287 | public function setLink(Membership $link): self { |
||
292 | |||
293 | /** |
||
294 | * @return Membership |
||
295 | */ |
||
296 | public function getLink(): Membership { |
||
299 | |||
300 | |||
301 | /** |
||
302 | * @param array $data |
||
303 | * |
||
304 | * @return $this |
||
305 | * @throws InvalidItemException |
||
306 | */ |
||
307 | public function import(array $data): IDeserializable { |
||
327 | |||
328 | |||
329 | /** |
||
330 | * @param Circle $circle |
||
331 | * |
||
332 | * @return FederatedUser |
||
333 | * @throws OwnerNotFoundException |
||
334 | */ |
||
335 | public function importFromCircle(Circle $circle): self { |
||
347 | |||
348 | |||
349 | /** |
||
350 | * @param array $data |
||
351 | * @param string $prefix |
||
352 | * |
||
353 | * @return INC22QueryRow |
||
354 | * @throws FederatedUserNotFoundException |
||
355 | */ |
||
356 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
370 | |||
371 | |||
372 | /** |
||
373 | * @return string[] |
||
374 | */ |
||
375 | public function jsonSerialize(): array { |
||
397 | |||
398 | |||
399 | /** |
||
400 | * @param IFederatedUser $member |
||
401 | * |
||
402 | * @return bool |
||
403 | */ |
||
404 | public function compareWith(IFederatedUser $member): bool { |
||
410 | |||
411 | } |
||
412 | |||
413 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.