Total Complexity | 53 |
Total Lines | 444 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like Product often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Product, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class Product extends AbstractEntity |
||
9 | { |
||
10 | protected string $availability; |
||
11 | protected int $available_in_days; |
||
12 | protected ?array $available_denominations; |
||
13 | protected ?string $barcode_format; |
||
14 | protected string $card_image_url; |
||
15 | protected string $logo_image_url; |
||
16 | protected array $categories; |
||
17 | protected string $code; |
||
18 | protected array $countries; |
||
19 | protected string $currency_code; |
||
20 | protected string $denomination_type; |
||
21 | protected string $description; |
||
22 | protected ?string $e_code_usage_type; |
||
23 | protected string $expiry_date_policy; |
||
24 | protected ?int $expiry_in_months; |
||
25 | protected float $maximum_value; |
||
26 | protected float $minimum_value; |
||
27 | protected string $name; |
||
28 | protected float $percent_discount; |
||
29 | protected string $redeem_instructions_html; |
||
30 | protected ?string $redeemable_at; |
||
31 | protected string $state; |
||
32 | protected string $terms_and_conditions_html; |
||
33 | protected string $terms_and_conditions_pdf_url; |
||
34 | protected bool $wrap_supported; |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | public function getAvailability(): string |
||
40 | { |
||
41 | return $this->availability; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @param string $availability |
||
46 | */ |
||
47 | public function setAvailability(string $availability): void |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return int |
||
54 | */ |
||
55 | public function getAvailableInDays(): int |
||
56 | { |
||
57 | return $this->available_in_days; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @param int $available_in_days |
||
62 | */ |
||
63 | public function setAvailableInDays(int $available_in_days): void |
||
64 | { |
||
65 | $this->available_in_days = $available_in_days; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function hasDenominations(): bool |
||
72 | { |
||
73 | return isset($this->available_denominations); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return array|null |
||
78 | */ |
||
79 | public function getAvailableDenominations(): ?array |
||
80 | { |
||
81 | return $this->available_denominations; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @param array|null $available_denominations |
||
86 | */ |
||
87 | public function setAvailableDenominations(?array $available_denominations): void |
||
88 | { |
||
89 | $this->available_denominations = $available_denominations; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @return string|null |
||
94 | */ |
||
95 | public function getBarcodeFormat(): ?string |
||
96 | { |
||
97 | return $this->barcode_format; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @param string|null $barcode_format |
||
102 | */ |
||
103 | public function setBarcodeFormat(?string $barcode_format): void |
||
104 | { |
||
105 | $this->barcode_format = $barcode_format; |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | public function getCardImageUrl(): string |
||
112 | { |
||
113 | return $this->card_image_url; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param string $card_image_url |
||
118 | */ |
||
119 | public function setCardImageUrl(string $card_image_url): void |
||
120 | { |
||
121 | $this->card_image_url = $card_image_url; |
||
122 | } |
||
123 | |||
124 | public function hasCardImageUrl(): bool |
||
125 | { |
||
126 | return isset($this->card_image_url); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getLogoImageUrl(): string |
||
133 | { |
||
134 | return $this->logo_image_url; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @param string $logo_image_url |
||
139 | */ |
||
140 | public function setLogoImageUrl(string $logo_image_url): void |
||
141 | { |
||
142 | $this->logo_image_url = $logo_image_url; |
||
143 | } |
||
144 | |||
145 | public function hasLogoImageUrl(): bool |
||
146 | { |
||
147 | return isset($this->logo_image_url); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return array |
||
152 | */ |
||
153 | public function getCategories(): array |
||
154 | { |
||
155 | return $this->categories; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @param array $categories |
||
160 | */ |
||
161 | public function setCategories(array $categories): void |
||
162 | { |
||
163 | $this->categories = $categories; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @return string |
||
168 | */ |
||
169 | public function getCode(): string |
||
170 | { |
||
171 | return $this->code; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @param string $code |
||
176 | */ |
||
177 | public function setCode(string $code): void |
||
178 | { |
||
179 | $this->code = $code; |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * @return array |
||
184 | */ |
||
185 | public function getCountries(): array |
||
186 | { |
||
187 | return $this->countries; |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * @param array $countries |
||
192 | */ |
||
193 | public function setCountries(array $countries): void |
||
194 | { |
||
195 | $this->countries = $countries; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @return string |
||
200 | */ |
||
201 | public function getCurrencyCode(): string |
||
202 | { |
||
203 | return $this->currency_code; |
||
204 | } |
||
205 | |||
206 | /** |
||
207 | * @param string $currency_code |
||
208 | */ |
||
209 | public function setCurrencyCode(string $currency_code): void |
||
210 | { |
||
211 | $this->currency_code = $currency_code; |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * @return string |
||
216 | */ |
||
217 | public function getDenominationType(): string |
||
218 | { |
||
219 | return $this->denomination_type; |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * @param string $denomination_type |
||
224 | */ |
||
225 | public function setDenominationType(string $denomination_type): void |
||
226 | { |
||
227 | $this->denomination_type = $denomination_type; |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getDescription(): string |
||
234 | { |
||
235 | return $this->description; |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * @param string $description |
||
240 | */ |
||
241 | public function setDescription(string $description): void |
||
242 | { |
||
243 | $this->description = $description; |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @return string|null |
||
248 | */ |
||
249 | public function getECodeUsageType(): ?string |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @param string|null $e_code_usage_type |
||
256 | */ |
||
257 | public function setECodeUsageType(?string $e_code_usage_type): void |
||
258 | { |
||
259 | $this->e_code_usage_type = $e_code_usage_type; |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * @return string |
||
264 | */ |
||
265 | public function getExpiryDatePolicy(): string |
||
266 | { |
||
267 | return $this->expiry_date_policy; |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * @param string $expiry_date_policy |
||
272 | */ |
||
273 | public function setExpiryDatePolicy(string $expiry_date_policy): void |
||
274 | { |
||
275 | $this->expiry_date_policy = $expiry_date_policy; |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * @return int|null |
||
280 | */ |
||
281 | public function getExpiryInMonths(): ?int |
||
282 | { |
||
283 | return $this->expiry_in_months; |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * @param int|null $expiry_in_months |
||
288 | */ |
||
289 | public function setExpiryInMonths(?int $expiry_in_months): void |
||
290 | { |
||
291 | $this->expiry_in_months = $expiry_in_months; |
||
292 | } |
||
293 | |||
294 | /** |
||
295 | * @return float |
||
296 | */ |
||
297 | public function getMaximumValue(): float |
||
298 | { |
||
299 | return $this->maximum_value; |
||
300 | } |
||
301 | |||
302 | /** |
||
303 | * @param float $maximum_value |
||
304 | */ |
||
305 | public function setMaximumValue(float $maximum_value): void |
||
306 | { |
||
307 | $this->maximum_value = $maximum_value; |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * @return float |
||
312 | */ |
||
313 | public function getMinimumValue(): float |
||
314 | { |
||
315 | return $this->minimum_value; |
||
316 | } |
||
317 | |||
318 | /** |
||
319 | * @param float $minimum_value |
||
320 | */ |
||
321 | public function setMinimumValue(float $minimum_value): void |
||
322 | { |
||
323 | $this->minimum_value = $minimum_value; |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * @return string |
||
328 | */ |
||
329 | public function getName(): string |
||
330 | { |
||
331 | return $this->name; |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * @param string $name |
||
336 | */ |
||
337 | public function setName(string $name): void |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * @return float |
||
344 | */ |
||
345 | public function getPercentDiscount(): float |
||
348 | } |
||
349 | |||
350 | /** |
||
351 | * @param float $percent_discount |
||
352 | */ |
||
353 | public function setPercentDiscount(float $percent_discount): void |
||
354 | { |
||
355 | $this->percent_discount = $percent_discount; |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * @return string |
||
360 | */ |
||
361 | public function getRedeemInstructionsHtml(): string |
||
362 | { |
||
363 | return $this->redeem_instructions_html; |
||
364 | } |
||
365 | |||
366 | /** |
||
367 | * @param string $redeem_instructions_html |
||
368 | */ |
||
369 | public function setRedeemInstructionsHtml(string $redeem_instructions_html): void |
||
370 | { |
||
371 | $this->redeem_instructions_html = $redeem_instructions_html; |
||
372 | } |
||
373 | |||
374 | /** |
||
375 | * @return string|null |
||
376 | */ |
||
377 | public function getRedeemableAt(): ?string |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * @param string|null $redeemable_at |
||
384 | */ |
||
385 | public function setRedeemableAt(?string $redeemable_at): void |
||
386 | { |
||
387 | $this->redeemable_at = $redeemable_at; |
||
388 | } |
||
389 | |||
390 | /** |
||
391 | * @return string |
||
392 | */ |
||
393 | public function getState(): string |
||
394 | { |
||
395 | return $this->state; |
||
396 | } |
||
397 | |||
398 | /** |
||
399 | * @param string $state |
||
400 | */ |
||
401 | public function setState(string $state): void |
||
402 | { |
||
403 | $this->state = $state; |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * @return string |
||
408 | */ |
||
409 | public function getTermsAndconditionsHtml(): string |
||
410 | { |
||
411 | return $this->terms_and_conditions_html; |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * @param string $terms_and_conditions_html |
||
416 | */ |
||
417 | public function setTermsAndconditionsHtml(string $terms_and_conditions_html): void |
||
418 | { |
||
419 | $this->terms_and_conditions_html = $terms_and_conditions_html; |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * @return string |
||
424 | */ |
||
425 | public function getTermsAndConditionsPdfUrl(): string |
||
426 | { |
||
427 | return $this->terms_and_conditions_pdf_url; |
||
428 | } |
||
429 | |||
430 | /** |
||
431 | * @param string $terms_and_conditions_pdf_url |
||
432 | */ |
||
433 | public function setTermsAndConditionsPdfUrl(string $terms_and_conditions_pdf_url): void |
||
436 | } |
||
437 | |||
438 | /** |
||
439 | * @return bool |
||
440 | */ |
||
441 | public function isWrapSupported(): bool |
||
442 | { |
||
443 | return $this->wrap_supported; |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * @param bool $wrap_supported |
||
448 | */ |
||
449 | public function setWrapSupported(bool $wrap_supported): void |
||
452 | } |
||
453 | } |
||
454 |