1 | <?php |
||
47 | class Membership extends ManagedModel implements IDeserializable, INC22QueryRow, JsonSerializable { |
||
48 | |||
49 | |||
50 | use TArrayTools; |
||
51 | |||
52 | |||
53 | /** @var string */ |
||
54 | private $singleId = ''; |
||
55 | |||
56 | /** @var string */ |
||
57 | private $circleId = ''; |
||
58 | |||
59 | /** @var int */ |
||
60 | private $circleConfig = 0; |
||
61 | |||
62 | /** @var int */ |
||
63 | private $level = 0; |
||
64 | |||
65 | /** @var string */ |
||
66 | private $inheritanceFirst = ''; |
||
67 | |||
68 | /** @var string */ |
||
69 | private $inheritanceLast = ''; |
||
70 | |||
71 | /** @var array */ |
||
72 | private $inheritancePath = []; |
||
73 | |||
74 | /** @var int */ |
||
75 | private $inheritanceDepth = 0; |
||
76 | |||
77 | /** @var array */ |
||
78 | private $inheritanceDetails = []; |
||
79 | |||
80 | |||
81 | /** |
||
82 | * Membership constructor. |
||
83 | * |
||
84 | * @param string $singleId |
||
85 | * @param Member|null $member |
||
86 | * @param string $inheritanceLast |
||
87 | */ |
||
88 | public function __construct( |
||
104 | |||
105 | |||
106 | /** |
||
107 | * @param string $singleId |
||
108 | * |
||
109 | * @return self |
||
110 | */ |
||
111 | public function setSingleId(string $singleId): self { |
||
116 | |||
117 | /** |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getSingleId(): string { |
||
123 | |||
124 | |||
125 | /** |
||
126 | * @param string $circleId |
||
127 | * |
||
128 | * @return Membership |
||
129 | */ |
||
130 | public function setCircleId(string $circleId): self { |
||
135 | |||
136 | /** |
||
137 | * @return string |
||
138 | */ |
||
139 | public function getCircleId(): string { |
||
142 | |||
143 | |||
144 | /** |
||
145 | * @param int $circleConfig |
||
146 | * |
||
147 | * @return Membership |
||
148 | */ |
||
149 | public function setCircleConfig(int $circleConfig): self { |
||
154 | |||
155 | /** |
||
156 | * @return int |
||
157 | */ |
||
158 | public function getCircleConfig(): int { |
||
161 | |||
162 | |||
163 | /** |
||
164 | * @param int $level |
||
165 | * |
||
166 | * @return Membership |
||
167 | */ |
||
168 | public function setLevel(int $level): self { |
||
173 | |||
174 | /** |
||
175 | * @return int |
||
176 | */ |
||
177 | public function getLevel(): int { |
||
180 | |||
181 | |||
182 | /** |
||
183 | * @param string $inheritanceFirst |
||
184 | * |
||
185 | * @return Membership |
||
186 | */ |
||
187 | public function setInheritanceFirst(string $inheritanceFirst): self { |
||
192 | |||
193 | /** |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getInheritanceFirst(): string { |
||
199 | |||
200 | |||
201 | /** |
||
202 | * @param string $inheritanceLast |
||
203 | * |
||
204 | * @return Membership |
||
205 | */ |
||
206 | public function setInheritanceLast(string $inheritanceLast): self { |
||
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getInheritanceLast(): string { |
||
218 | |||
219 | |||
220 | /** |
||
221 | * @param array $inheritancePath |
||
222 | * |
||
223 | * @return Membership |
||
224 | */ |
||
225 | public function setInheritancePath(array $inheritancePath): self { |
||
230 | |||
231 | /** |
||
232 | * @return array |
||
233 | */ |
||
234 | public function getInheritancePath(): array { |
||
237 | |||
238 | |||
239 | /** |
||
240 | * @param int $inheritanceDepth |
||
241 | * |
||
242 | * @return Membership |
||
243 | */ |
||
244 | public function setInheritanceDepth(int $inheritanceDepth): self { |
||
249 | |||
250 | /** |
||
251 | * @return int |
||
252 | */ |
||
253 | public function getInheritanceDepth(): int { |
||
256 | |||
257 | |||
258 | /** |
||
259 | * @param array $inheritanceDetails |
||
260 | * |
||
261 | * @return Membership |
||
262 | */ |
||
263 | public function setInheritanceDetails(array $inheritanceDetails): self { |
||
268 | |||
269 | /** |
||
270 | * @return array |
||
271 | */ |
||
272 | public function getInheritanceDetails(): array { |
||
275 | |||
276 | |||
277 | /** |
||
278 | * @param array $data |
||
279 | * |
||
280 | * @return IDeserializable |
||
281 | * @throws InvalidItemException |
||
282 | */ |
||
283 | public function import(array $data): IDeserializable { |
||
299 | |||
300 | /** |
||
301 | * @param array $data |
||
302 | * @param string $prefix |
||
303 | * |
||
304 | * @return INC22QueryRow |
||
305 | * @throws MembershipNotFoundException |
||
306 | */ |
||
307 | public function importFromDatabase(array $data, string $prefix = ''): INC22QueryRow { |
||
323 | |||
324 | |||
325 | /** |
||
326 | * @return array |
||
327 | */ |
||
328 | public function jsonSerialize(): array { |
||
346 | |||
347 | } |
||
348 | |||
349 |
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.