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