Total Complexity | 46 |
Total Lines | 622 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ProductModel 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 ProductModel, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class ProductModel |
||
6 | { |
||
7 | /** |
||
8 | * |
||
9 | * |
||
10 | * @var int |
||
11 | */ |
||
12 | protected $productId; |
||
13 | /** |
||
14 | * A timestamp of when the product was created. The time should be formatted using ISO-8601 |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $createdAt; |
||
19 | /** |
||
20 | * The default vat rate for this product. Will fall back to shop default if null. To fetch country specific vat rates, please use include=vatRates or use the /products/x/vat-rates endpoint. |
||
21 | * |
||
22 | * @var string|null |
||
23 | */ |
||
24 | protected $defaultVatRate; |
||
25 | /** |
||
26 | * The visibility of this product. Supported values are: hidden, visible, pricelists |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $visibility = 'hidden'; |
||
31 | /** |
||
32 | * The ID´s of the pricelists that the product should be visible for. Is required for when ”visibility” is set to ”pricelists” but should never be populated otherwise |
||
33 | * |
||
34 | * @var int[] |
||
35 | */ |
||
36 | protected $visibilityPricelistIds; |
||
37 | /** |
||
38 | * A valid URL to a web page with more information for this product |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $moreInfoUrl; |
||
43 | /** |
||
44 | * The id of the manufacturer to use for this product. Fetch and handle available manufacturers using the /product-manufacturers endpoint |
||
45 | * |
||
46 | * @var int|null |
||
47 | */ |
||
48 | protected $manufacturerId; |
||
49 | /** |
||
50 | * The id of the unit to use for this product if not standard. Fetch and handle available units using the /product-units endpoint |
||
51 | * |
||
52 | * @var int|null |
||
53 | */ |
||
54 | protected $unitId; |
||
55 | /** |
||
56 | * Sort index for this product in a list |
||
57 | * |
||
58 | * @var int|null |
||
59 | */ |
||
60 | protected $sortIndex; |
||
61 | /** |
||
62 | * The type of product. Either ”basic” or ”bundle”. Default is ”basic” |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $type; |
||
67 | /** |
||
68 | * Should this product be watchable for customers when it is back in stock? |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $isBackInStockWatchable = true; |
||
73 | /** |
||
74 | * Should all bundled products have a manually entered price? Only applies if type is bundle |
||
75 | * |
||
76 | * @var bool |
||
77 | */ |
||
78 | protected $bundleUseManualPrice; |
||
79 | /** |
||
80 | * Account number for managing accounting on product level |
||
81 | * |
||
82 | * @var int|null |
||
83 | */ |
||
84 | protected $accounting; |
||
85 | /** |
||
86 | * Indicates if the products has several variants or not. The remaining variants can be fetched using the /products/{product id}/variants endpoint |
||
87 | * |
||
88 | * @var bool |
||
89 | */ |
||
90 | protected $hasSeveralVariants; |
||
91 | /** |
||
92 | * A timestamp of when the product was modified. The time should be formatted using ISO-8601 |
||
93 | * |
||
94 | * @var string |
||
95 | */ |
||
96 | protected $modifiedAt; |
||
97 | /** |
||
98 | * |
||
99 | * |
||
100 | * @var ProductVariantModelCollection |
||
101 | */ |
||
102 | protected $variants; |
||
103 | /** |
||
104 | * |
||
105 | * |
||
106 | * @var BundledProductsModelCollection |
||
107 | */ |
||
108 | protected $bundledProducts; |
||
109 | /** |
||
110 | * |
||
111 | * |
||
112 | * @var ProductMediaFileLinkModelCollection |
||
113 | */ |
||
114 | protected $mediaFiles; |
||
115 | /** |
||
116 | * |
||
117 | * |
||
118 | * @var ProductModelLanguages |
||
119 | */ |
||
120 | protected $languages; |
||
121 | /** |
||
122 | * |
||
123 | * |
||
124 | * @var ProductVatRateModelCollection |
||
125 | */ |
||
126 | protected $vatRates; |
||
127 | /** |
||
128 | * |
||
129 | * |
||
130 | * @var ProductCategoryLinkModelCollection |
||
131 | */ |
||
132 | protected $categories; |
||
133 | /** |
||
134 | * |
||
135 | * |
||
136 | * @var ProductUnitModelItem |
||
137 | */ |
||
138 | protected $unit; |
||
139 | /** |
||
140 | * |
||
141 | * |
||
142 | * @var ProductMetaDataModelCollection |
||
143 | */ |
||
144 | protected $metaData; |
||
145 | /** |
||
146 | * |
||
147 | * |
||
148 | * @return int |
||
149 | */ |
||
150 | public function getProductId() : int |
||
151 | { |
||
152 | return $this->productId; |
||
153 | } |
||
154 | /** |
||
155 | * |
||
156 | * |
||
157 | * @param int $productId |
||
158 | * |
||
159 | * @return self |
||
160 | */ |
||
161 | public function setProductId(int $productId) : self |
||
162 | { |
||
163 | $this->productId = $productId; |
||
164 | return $this; |
||
165 | } |
||
166 | /** |
||
167 | * A timestamp of when the product was created. The time should be formatted using ISO-8601 |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | public function getCreatedAt() : string |
||
172 | { |
||
173 | return $this->createdAt; |
||
174 | } |
||
175 | /** |
||
176 | * A timestamp of when the product was created. The time should be formatted using ISO-8601 |
||
177 | * |
||
178 | * @param string $createdAt |
||
179 | * |
||
180 | * @return self |
||
181 | */ |
||
182 | public function setCreatedAt(string $createdAt) : self |
||
183 | { |
||
184 | $this->createdAt = $createdAt; |
||
185 | return $this; |
||
186 | } |
||
187 | /** |
||
188 | * The default vat rate for this product. Will fall back to shop default if null. To fetch country specific vat rates, please use include=vatRates or use the /products/x/vat-rates endpoint. |
||
189 | * |
||
190 | * @return string|null |
||
191 | */ |
||
192 | public function getDefaultVatRate() : ?string |
||
193 | { |
||
194 | return $this->defaultVatRate; |
||
195 | } |
||
196 | /** |
||
197 | * The default vat rate for this product. Will fall back to shop default if null. To fetch country specific vat rates, please use include=vatRates or use the /products/x/vat-rates endpoint. |
||
198 | * |
||
199 | * @param string|null $defaultVatRate |
||
200 | * |
||
201 | * @return self |
||
202 | */ |
||
203 | public function setDefaultVatRate(?string $defaultVatRate) : self |
||
204 | { |
||
205 | $this->defaultVatRate = $defaultVatRate; |
||
206 | return $this; |
||
207 | } |
||
208 | /** |
||
209 | * The visibility of this product. Supported values are: hidden, visible, pricelists |
||
210 | * |
||
211 | * @return string |
||
212 | */ |
||
213 | public function getVisibility() : string |
||
214 | { |
||
215 | return $this->visibility; |
||
216 | } |
||
217 | /** |
||
218 | * The visibility of this product. Supported values are: hidden, visible, pricelists |
||
219 | * |
||
220 | * @param string $visibility |
||
221 | * |
||
222 | * @return self |
||
223 | */ |
||
224 | public function setVisibility(string $visibility) : self |
||
225 | { |
||
226 | $this->visibility = $visibility; |
||
227 | return $this; |
||
228 | } |
||
229 | /** |
||
230 | * The ID´s of the pricelists that the product should be visible for. Is required for when ”visibility” is set to ”pricelists” but should never be populated otherwise |
||
231 | * |
||
232 | * @return int[] |
||
233 | */ |
||
234 | public function getVisibilityPricelistIds() : array |
||
235 | { |
||
236 | return $this->visibilityPricelistIds; |
||
237 | } |
||
238 | /** |
||
239 | * The ID´s of the pricelists that the product should be visible for. Is required for when ”visibility” is set to ”pricelists” but should never be populated otherwise |
||
240 | * |
||
241 | * @param int[] $visibilityPricelistIds |
||
242 | * |
||
243 | * @return self |
||
244 | */ |
||
245 | public function setVisibilityPricelistIds(array $visibilityPricelistIds) : self |
||
246 | { |
||
247 | $this->visibilityPricelistIds = $visibilityPricelistIds; |
||
248 | return $this; |
||
249 | } |
||
250 | /** |
||
251 | * A valid URL to a web page with more information for this product |
||
252 | * |
||
253 | * @return string |
||
254 | */ |
||
255 | public function getMoreInfoUrl() : string |
||
256 | { |
||
257 | return $this->moreInfoUrl; |
||
258 | } |
||
259 | /** |
||
260 | * A valid URL to a web page with more information for this product |
||
261 | * |
||
262 | * @param string $moreInfoUrl |
||
263 | * |
||
264 | * @return self |
||
265 | */ |
||
266 | public function setMoreInfoUrl(string $moreInfoUrl) : self |
||
267 | { |
||
268 | $this->moreInfoUrl = $moreInfoUrl; |
||
269 | return $this; |
||
270 | } |
||
271 | /** |
||
272 | * The id of the manufacturer to use for this product. Fetch and handle available manufacturers using the /product-manufacturers endpoint |
||
273 | * |
||
274 | * @return int|null |
||
275 | */ |
||
276 | public function getManufacturerId() : ?int |
||
277 | { |
||
278 | return $this->manufacturerId; |
||
279 | } |
||
280 | /** |
||
281 | * The id of the manufacturer to use for this product. Fetch and handle available manufacturers using the /product-manufacturers endpoint |
||
282 | * |
||
283 | * @param int|null $manufacturerId |
||
284 | * |
||
285 | * @return self |
||
286 | */ |
||
287 | public function setManufacturerId(?int $manufacturerId) : self |
||
288 | { |
||
289 | $this->manufacturerId = $manufacturerId; |
||
290 | return $this; |
||
291 | } |
||
292 | /** |
||
293 | * The id of the unit to use for this product if not standard. Fetch and handle available units using the /product-units endpoint |
||
294 | * |
||
295 | * @return int|null |
||
296 | */ |
||
297 | public function getUnitId() : ?int |
||
298 | { |
||
299 | return $this->unitId; |
||
300 | } |
||
301 | /** |
||
302 | * The id of the unit to use for this product if not standard. Fetch and handle available units using the /product-units endpoint |
||
303 | * |
||
304 | * @param int|null $unitId |
||
305 | * |
||
306 | * @return self |
||
307 | */ |
||
308 | public function setUnitId(?int $unitId) : self |
||
309 | { |
||
310 | $this->unitId = $unitId; |
||
311 | return $this; |
||
312 | } |
||
313 | /** |
||
314 | * Sort index for this product in a list |
||
315 | * |
||
316 | * @return int|null |
||
317 | */ |
||
318 | public function getSortIndex() : ?int |
||
321 | } |
||
322 | /** |
||
323 | * Sort index for this product in a list |
||
324 | * |
||
325 | * @param int|null $sortIndex |
||
326 | * |
||
327 | * @return self |
||
328 | */ |
||
329 | public function setSortIndex(?int $sortIndex) : self |
||
330 | { |
||
331 | $this->sortIndex = $sortIndex; |
||
332 | return $this; |
||
333 | } |
||
334 | /** |
||
335 | * The type of product. Either ”basic” or ”bundle”. Default is ”basic” |
||
336 | * |
||
337 | * @return string |
||
338 | */ |
||
339 | public function getType() : string |
||
340 | { |
||
341 | return $this->type; |
||
342 | } |
||
343 | /** |
||
344 | * The type of product. Either ”basic” or ”bundle”. Default is ”basic” |
||
345 | * |
||
346 | * @param string $type |
||
347 | * |
||
348 | * @return self |
||
349 | */ |
||
350 | public function setType(string $type) : self |
||
351 | { |
||
352 | $this->type = $type; |
||
353 | return $this; |
||
354 | } |
||
355 | /** |
||
356 | * Should this product be watchable for customers when it is back in stock? |
||
357 | * |
||
358 | * @return bool |
||
359 | */ |
||
360 | public function getIsBackInStockWatchable() : bool |
||
361 | { |
||
362 | return $this->isBackInStockWatchable; |
||
363 | } |
||
364 | /** |
||
365 | * Should this product be watchable for customers when it is back in stock? |
||
366 | * |
||
367 | * @param bool $isBackInStockWatchable |
||
368 | * |
||
369 | * @return self |
||
370 | */ |
||
371 | public function setIsBackInStockWatchable(bool $isBackInStockWatchable) : self |
||
372 | { |
||
373 | $this->isBackInStockWatchable = $isBackInStockWatchable; |
||
374 | return $this; |
||
375 | } |
||
376 | /** |
||
377 | * Should all bundled products have a manually entered price? Only applies if type is bundle |
||
378 | * |
||
379 | * @return bool |
||
380 | */ |
||
381 | public function getBundleUseManualPrice() : bool |
||
382 | { |
||
383 | return $this->bundleUseManualPrice; |
||
384 | } |
||
385 | /** |
||
386 | * Should all bundled products have a manually entered price? Only applies if type is bundle |
||
387 | * |
||
388 | * @param bool $bundleUseManualPrice |
||
389 | * |
||
390 | * @return self |
||
391 | */ |
||
392 | public function setBundleUseManualPrice(bool $bundleUseManualPrice) : self |
||
393 | { |
||
394 | $this->bundleUseManualPrice = $bundleUseManualPrice; |
||
395 | return $this; |
||
396 | } |
||
397 | /** |
||
398 | * Account number for managing accounting on product level |
||
399 | * |
||
400 | * @return int|null |
||
401 | */ |
||
402 | public function getAccounting() : ?int |
||
403 | { |
||
404 | return $this->accounting; |
||
405 | } |
||
406 | /** |
||
407 | * Account number for managing accounting on product level |
||
408 | * |
||
409 | * @param int|null $accounting |
||
410 | * |
||
411 | * @return self |
||
412 | */ |
||
413 | public function setAccounting(?int $accounting) : self |
||
414 | { |
||
415 | $this->accounting = $accounting; |
||
416 | return $this; |
||
417 | } |
||
418 | /** |
||
419 | * Indicates if the products has several variants or not. The remaining variants can be fetched using the /products/{product id}/variants endpoint |
||
420 | * |
||
421 | * @return bool |
||
422 | */ |
||
423 | public function getHasSeveralVariants() : bool |
||
424 | { |
||
425 | return $this->hasSeveralVariants; |
||
426 | } |
||
427 | /** |
||
428 | * Indicates if the products has several variants or not. The remaining variants can be fetched using the /products/{product id}/variants endpoint |
||
429 | * |
||
430 | * @param bool $hasSeveralVariants |
||
431 | * |
||
432 | * @return self |
||
433 | */ |
||
434 | public function setHasSeveralVariants(bool $hasSeveralVariants) : self |
||
435 | { |
||
436 | $this->hasSeveralVariants = $hasSeveralVariants; |
||
437 | return $this; |
||
438 | } |
||
439 | /** |
||
440 | * A timestamp of when the product was modified. The time should be formatted using ISO-8601 |
||
441 | * |
||
442 | * @return string |
||
443 | */ |
||
444 | public function getModifiedAt() : string |
||
445 | { |
||
446 | return $this->modifiedAt; |
||
447 | } |
||
448 | /** |
||
449 | * A timestamp of when the product was modified. The time should be formatted using ISO-8601 |
||
450 | * |
||
451 | * @param string $modifiedAt |
||
452 | * |
||
453 | * @return self |
||
454 | */ |
||
455 | public function setModifiedAt(string $modifiedAt) : self |
||
456 | { |
||
457 | $this->modifiedAt = $modifiedAt; |
||
458 | return $this; |
||
459 | } |
||
460 | /** |
||
461 | * |
||
462 | * |
||
463 | * @return ProductVariantModelCollection |
||
464 | */ |
||
465 | public function getVariants() : ProductVariantModelCollection |
||
466 | { |
||
467 | return $this->variants; |
||
468 | } |
||
469 | /** |
||
470 | * |
||
471 | * |
||
472 | * @param ProductVariantModelCollection $variants |
||
473 | * |
||
474 | * @return self |
||
475 | */ |
||
476 | public function setVariants(ProductVariantModelCollection $variants) : self |
||
477 | { |
||
478 | $this->variants = $variants; |
||
479 | return $this; |
||
480 | } |
||
481 | /** |
||
482 | * |
||
483 | * |
||
484 | * @return BundledProductsModelCollection |
||
485 | */ |
||
486 | public function getBundledProducts() : BundledProductsModelCollection |
||
487 | { |
||
488 | return $this->bundledProducts; |
||
489 | } |
||
490 | /** |
||
491 | * |
||
492 | * |
||
493 | * @param BundledProductsModelCollection $bundledProducts |
||
494 | * |
||
495 | * @return self |
||
496 | */ |
||
497 | public function setBundledProducts(BundledProductsModelCollection $bundledProducts) : self |
||
498 | { |
||
499 | $this->bundledProducts = $bundledProducts; |
||
500 | return $this; |
||
501 | } |
||
502 | /** |
||
503 | * |
||
504 | * |
||
505 | * @return ProductMediaFileLinkModelCollection |
||
506 | */ |
||
507 | public function getMediaFiles() : ProductMediaFileLinkModelCollection |
||
508 | { |
||
509 | return $this->mediaFiles; |
||
510 | } |
||
511 | /** |
||
512 | * |
||
513 | * |
||
514 | * @param ProductMediaFileLinkModelCollection $mediaFiles |
||
515 | * |
||
516 | * @return self |
||
517 | */ |
||
518 | public function setMediaFiles(ProductMediaFileLinkModelCollection $mediaFiles) : self |
||
519 | { |
||
520 | $this->mediaFiles = $mediaFiles; |
||
521 | return $this; |
||
522 | } |
||
523 | /** |
||
524 | * |
||
525 | * |
||
526 | * @return ProductModelLanguages |
||
527 | */ |
||
528 | public function getLanguages() : ProductModelLanguages |
||
531 | } |
||
532 | /** |
||
533 | * |
||
534 | * |
||
535 | * @param ProductModelLanguages $languages |
||
536 | * |
||
537 | * @return self |
||
538 | */ |
||
539 | public function setLanguages(ProductModelLanguages $languages) : self |
||
540 | { |
||
541 | $this->languages = $languages; |
||
542 | return $this; |
||
543 | } |
||
544 | /** |
||
545 | * |
||
546 | * |
||
547 | * @return ProductVatRateModelCollection |
||
548 | */ |
||
549 | public function getVatRates() : ProductVatRateModelCollection |
||
550 | { |
||
551 | return $this->vatRates; |
||
552 | } |
||
553 | /** |
||
554 | * |
||
555 | * |
||
556 | * @param ProductVatRateModelCollection $vatRates |
||
557 | * |
||
558 | * @return self |
||
559 | */ |
||
560 | public function setVatRates(ProductVatRateModelCollection $vatRates) : self |
||
561 | { |
||
562 | $this->vatRates = $vatRates; |
||
563 | return $this; |
||
564 | } |
||
565 | /** |
||
566 | * |
||
567 | * |
||
568 | * @return ProductCategoryLinkModelCollection |
||
569 | */ |
||
570 | public function getCategories() : ProductCategoryLinkModelCollection |
||
571 | { |
||
572 | return $this->categories; |
||
573 | } |
||
574 | /** |
||
575 | * |
||
576 | * |
||
577 | * @param ProductCategoryLinkModelCollection $categories |
||
578 | * |
||
579 | * @return self |
||
580 | */ |
||
581 | public function setCategories(ProductCategoryLinkModelCollection $categories) : self |
||
582 | { |
||
583 | $this->categories = $categories; |
||
584 | return $this; |
||
585 | } |
||
586 | /** |
||
587 | * |
||
588 | * |
||
589 | * @return ProductUnitModelItem |
||
590 | */ |
||
591 | public function getUnit() : ProductUnitModelItem |
||
594 | } |
||
595 | /** |
||
596 | * |
||
597 | * |
||
598 | * @param ProductUnitModelItem $unit |
||
599 | * |
||
600 | * @return self |
||
601 | */ |
||
602 | public function setUnit(ProductUnitModelItem $unit) : self |
||
606 | } |
||
607 | /** |
||
608 | * |
||
609 | * |
||
610 | * @return ProductMetaDataModelCollection |
||
611 | */ |
||
612 | public function getMetaData() : ProductMetaDataModelCollection |
||
613 | { |
||
614 | return $this->metaData; |
||
615 | } |
||
616 | /** |
||
617 | * |
||
618 | * |
||
619 | * @param ProductMetaDataModelCollection $metaData |
||
620 | * |
||
621 | * @return self |
||
622 | */ |
||
623 | public function setMetaData(ProductMetaDataModelCollection $metaData) : self |
||
624 | { |
||
625 | $this->metaData = $metaData; |
||
626 | return $this; |
||
627 | } |
||
628 | } |