Total Complexity | 40 |
Total Lines | 541 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ProductModelPatchable 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 ProductModelPatchable, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class ProductModelPatchable |
||
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 | * A collection of media files |
||
99 | * |
||
100 | * @var ProductMediaFileLinkModel[] |
||
101 | */ |
||
102 | protected $mediaFiles; |
||
103 | /** |
||
104 | * A collection of product languages |
||
105 | * |
||
106 | * @var ProductLanguageModel[] |
||
107 | */ |
||
108 | protected $languages; |
||
109 | /** |
||
110 | * A collection of country specific vat rates |
||
111 | * |
||
112 | * @var ProductVatRateModel[] |
||
113 | */ |
||
114 | protected $vatRates; |
||
115 | /** |
||
116 | * A collection of categories |
||
117 | * |
||
118 | * @var ProductCategoryLinkModel[] |
||
119 | */ |
||
120 | protected $categories; |
||
121 | /** |
||
122 | * A collection of meta data |
||
123 | * |
||
124 | * @var ProductMetaDataModelUpdatable[] |
||
125 | */ |
||
126 | protected $metaData; |
||
127 | /** |
||
128 | * |
||
129 | * |
||
130 | * @return int |
||
131 | */ |
||
132 | public function getProductId() : int |
||
133 | { |
||
134 | return $this->productId; |
||
135 | } |
||
136 | /** |
||
137 | * |
||
138 | * |
||
139 | * @param int $productId |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | public function setProductId(int $productId) : self |
||
147 | } |
||
148 | /** |
||
149 | * A timestamp of when the product was created. The time should be formatted using ISO-8601 |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getCreatedAt() : string |
||
154 | { |
||
155 | return $this->createdAt; |
||
156 | } |
||
157 | /** |
||
158 | * A timestamp of when the product was created. The time should be formatted using ISO-8601 |
||
159 | * |
||
160 | * @param string $createdAt |
||
161 | * |
||
162 | * @return self |
||
163 | */ |
||
164 | public function setCreatedAt(string $createdAt) : self |
||
165 | { |
||
166 | $this->createdAt = $createdAt; |
||
167 | return $this; |
||
168 | } |
||
169 | /** |
||
170 | * 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. |
||
171 | * |
||
172 | * @return string|null |
||
173 | */ |
||
174 | public function getDefaultVatRate() : ?string |
||
175 | { |
||
176 | return $this->defaultVatRate; |
||
177 | } |
||
178 | /** |
||
179 | * 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. |
||
180 | * |
||
181 | * @param string|null $defaultVatRate |
||
182 | * |
||
183 | * @return self |
||
184 | */ |
||
185 | public function setDefaultVatRate(?string $defaultVatRate) : self |
||
186 | { |
||
187 | $this->defaultVatRate = $defaultVatRate; |
||
188 | return $this; |
||
189 | } |
||
190 | /** |
||
191 | * The visibility of this product. Supported values are: hidden, visible, pricelists |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getVisibility() : string |
||
196 | { |
||
197 | return $this->visibility; |
||
198 | } |
||
199 | /** |
||
200 | * The visibility of this product. Supported values are: hidden, visible, pricelists |
||
201 | * |
||
202 | * @param string $visibility |
||
203 | * |
||
204 | * @return self |
||
205 | */ |
||
206 | public function setVisibility(string $visibility) : self |
||
207 | { |
||
208 | $this->visibility = $visibility; |
||
209 | return $this; |
||
210 | } |
||
211 | /** |
||
212 | * 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 |
||
213 | * |
||
214 | * @return int[] |
||
215 | */ |
||
216 | public function getVisibilityPricelistIds() : array |
||
217 | { |
||
218 | return $this->visibilityPricelistIds; |
||
219 | } |
||
220 | /** |
||
221 | * 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 |
||
222 | * |
||
223 | * @param int[] $visibilityPricelistIds |
||
224 | * |
||
225 | * @return self |
||
226 | */ |
||
227 | public function setVisibilityPricelistIds(array $visibilityPricelistIds) : self |
||
228 | { |
||
229 | $this->visibilityPricelistIds = $visibilityPricelistIds; |
||
230 | return $this; |
||
231 | } |
||
232 | /** |
||
233 | * A valid URL to a web page with more information for this product |
||
234 | * |
||
235 | * @return string |
||
236 | */ |
||
237 | public function getMoreInfoUrl() : string |
||
238 | { |
||
239 | return $this->moreInfoUrl; |
||
240 | } |
||
241 | /** |
||
242 | * A valid URL to a web page with more information for this product |
||
243 | * |
||
244 | * @param string $moreInfoUrl |
||
245 | * |
||
246 | * @return self |
||
247 | */ |
||
248 | public function setMoreInfoUrl(string $moreInfoUrl) : self |
||
249 | { |
||
250 | $this->moreInfoUrl = $moreInfoUrl; |
||
251 | return $this; |
||
252 | } |
||
253 | /** |
||
254 | * The id of the manufacturer to use for this product. Fetch and handle available manufacturers using the /product-manufacturers endpoint |
||
255 | * |
||
256 | * @return int|null |
||
257 | */ |
||
258 | public function getManufacturerId() : ?int |
||
259 | { |
||
260 | return $this->manufacturerId; |
||
261 | } |
||
262 | /** |
||
263 | * The id of the manufacturer to use for this product. Fetch and handle available manufacturers using the /product-manufacturers endpoint |
||
264 | * |
||
265 | * @param int|null $manufacturerId |
||
266 | * |
||
267 | * @return self |
||
268 | */ |
||
269 | public function setManufacturerId(?int $manufacturerId) : self |
||
270 | { |
||
271 | $this->manufacturerId = $manufacturerId; |
||
272 | return $this; |
||
273 | } |
||
274 | /** |
||
275 | * The id of the unit to use for this product if not standard. Fetch and handle available units using the /product-units endpoint |
||
276 | * |
||
277 | * @return int|null |
||
278 | */ |
||
279 | public function getUnitId() : ?int |
||
280 | { |
||
281 | return $this->unitId; |
||
282 | } |
||
283 | /** |
||
284 | * The id of the unit to use for this product if not standard. Fetch and handle available units using the /product-units endpoint |
||
285 | * |
||
286 | * @param int|null $unitId |
||
287 | * |
||
288 | * @return self |
||
289 | */ |
||
290 | public function setUnitId(?int $unitId) : self |
||
291 | { |
||
292 | $this->unitId = $unitId; |
||
293 | return $this; |
||
294 | } |
||
295 | /** |
||
296 | * Sort index for this product in a list |
||
297 | * |
||
298 | * @return int|null |
||
299 | */ |
||
300 | public function getSortIndex() : ?int |
||
301 | { |
||
302 | return $this->sortIndex; |
||
303 | } |
||
304 | /** |
||
305 | * Sort index for this product in a list |
||
306 | * |
||
307 | * @param int|null $sortIndex |
||
308 | * |
||
309 | * @return self |
||
310 | */ |
||
311 | public function setSortIndex(?int $sortIndex) : self |
||
312 | { |
||
313 | $this->sortIndex = $sortIndex; |
||
314 | return $this; |
||
315 | } |
||
316 | /** |
||
317 | * The type of product. Either ”basic” or ”bundle”. Default is ”basic” |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | public function getType() : string |
||
322 | { |
||
323 | return $this->type; |
||
324 | } |
||
325 | /** |
||
326 | * The type of product. Either ”basic” or ”bundle”. Default is ”basic” |
||
327 | * |
||
328 | * @param string $type |
||
329 | * |
||
330 | * @return self |
||
331 | */ |
||
332 | public function setType(string $type) : self |
||
333 | { |
||
334 | $this->type = $type; |
||
335 | return $this; |
||
336 | } |
||
337 | /** |
||
338 | * Should this product be watchable for customers when it is back in stock? |
||
339 | * |
||
340 | * @return bool |
||
341 | */ |
||
342 | public function getIsBackInStockWatchable() : bool |
||
345 | } |
||
346 | /** |
||
347 | * Should this product be watchable for customers when it is back in stock? |
||
348 | * |
||
349 | * @param bool $isBackInStockWatchable |
||
350 | * |
||
351 | * @return self |
||
352 | */ |
||
353 | public function setIsBackInStockWatchable(bool $isBackInStockWatchable) : self |
||
354 | { |
||
355 | $this->isBackInStockWatchable = $isBackInStockWatchable; |
||
356 | return $this; |
||
357 | } |
||
358 | /** |
||
359 | * Should all bundled products have a manually entered price? Only applies if type is bundle |
||
360 | * |
||
361 | * @return bool |
||
362 | */ |
||
363 | public function getBundleUseManualPrice() : bool |
||
364 | { |
||
365 | return $this->bundleUseManualPrice; |
||
366 | } |
||
367 | /** |
||
368 | * Should all bundled products have a manually entered price? Only applies if type is bundle |
||
369 | * |
||
370 | * @param bool $bundleUseManualPrice |
||
371 | * |
||
372 | * @return self |
||
373 | */ |
||
374 | public function setBundleUseManualPrice(bool $bundleUseManualPrice) : self |
||
375 | { |
||
376 | $this->bundleUseManualPrice = $bundleUseManualPrice; |
||
377 | return $this; |
||
378 | } |
||
379 | /** |
||
380 | * Account number for managing accounting on product level |
||
381 | * |
||
382 | * @return int|null |
||
383 | */ |
||
384 | public function getAccounting() : ?int |
||
385 | { |
||
386 | return $this->accounting; |
||
387 | } |
||
388 | /** |
||
389 | * Account number for managing accounting on product level |
||
390 | * |
||
391 | * @param int|null $accounting |
||
392 | * |
||
393 | * @return self |
||
394 | */ |
||
395 | public function setAccounting(?int $accounting) : self |
||
396 | { |
||
397 | $this->accounting = $accounting; |
||
398 | return $this; |
||
399 | } |
||
400 | /** |
||
401 | * Indicates if the products has several variants or not. The remaining variants can be fetched using the /products/{product id}/variants endpoint |
||
402 | * |
||
403 | * @return bool |
||
404 | */ |
||
405 | public function getHasSeveralVariants() : bool |
||
406 | { |
||
407 | return $this->hasSeveralVariants; |
||
408 | } |
||
409 | /** |
||
410 | * Indicates if the products has several variants or not. The remaining variants can be fetched using the /products/{product id}/variants endpoint |
||
411 | * |
||
412 | * @param bool $hasSeveralVariants |
||
413 | * |
||
414 | * @return self |
||
415 | */ |
||
416 | public function setHasSeveralVariants(bool $hasSeveralVariants) : self |
||
420 | } |
||
421 | /** |
||
422 | * A timestamp of when the product was modified. The time should be formatted using ISO-8601 |
||
423 | * |
||
424 | * @return string |
||
425 | */ |
||
426 | public function getModifiedAt() : string |
||
427 | { |
||
428 | return $this->modifiedAt; |
||
429 | } |
||
430 | /** |
||
431 | * A timestamp of when the product was modified. The time should be formatted using ISO-8601 |
||
432 | * |
||
433 | * @param string $modifiedAt |
||
434 | * |
||
435 | * @return self |
||
436 | */ |
||
437 | public function setModifiedAt(string $modifiedAt) : self |
||
438 | { |
||
439 | $this->modifiedAt = $modifiedAt; |
||
440 | return $this; |
||
441 | } |
||
442 | /** |
||
443 | * A collection of media files |
||
444 | * |
||
445 | * @return ProductMediaFileLinkModel[] |
||
446 | */ |
||
447 | public function getMediaFiles() : array |
||
448 | { |
||
449 | return $this->mediaFiles; |
||
450 | } |
||
451 | /** |
||
452 | * A collection of media files |
||
453 | * |
||
454 | * @param ProductMediaFileLinkModel[] $mediaFiles |
||
455 | * |
||
456 | * @return self |
||
457 | */ |
||
458 | public function setMediaFiles(array $mediaFiles) : self |
||
462 | } |
||
463 | /** |
||
464 | * A collection of product languages |
||
465 | * |
||
466 | * @return ProductLanguageModel[] |
||
467 | */ |
||
468 | public function getLanguages() : array |
||
469 | { |
||
470 | return $this->languages; |
||
471 | } |
||
472 | /** |
||
473 | * A collection of product languages |
||
474 | * |
||
475 | * @param ProductLanguageModel[] $languages |
||
476 | * |
||
477 | * @return self |
||
478 | */ |
||
479 | public function setLanguages(array $languages) : self |
||
480 | { |
||
481 | $this->languages = $languages; |
||
482 | return $this; |
||
483 | } |
||
484 | /** |
||
485 | * A collection of country specific vat rates |
||
486 | * |
||
487 | * @return ProductVatRateModel[] |
||
488 | */ |
||
489 | public function getVatRates() : array |
||
490 | { |
||
491 | return $this->vatRates; |
||
492 | } |
||
493 | /** |
||
494 | * A collection of country specific vat rates |
||
495 | * |
||
496 | * @param ProductVatRateModel[] $vatRates |
||
497 | * |
||
498 | * @return self |
||
499 | */ |
||
500 | public function setVatRates(array $vatRates) : self |
||
501 | { |
||
502 | $this->vatRates = $vatRates; |
||
503 | return $this; |
||
504 | } |
||
505 | /** |
||
506 | * A collection of categories |
||
507 | * |
||
508 | * @return ProductCategoryLinkModel[] |
||
509 | */ |
||
510 | public function getCategories() : array |
||
513 | } |
||
514 | /** |
||
515 | * A collection of categories |
||
516 | * |
||
517 | * @param ProductCategoryLinkModel[] $categories |
||
518 | * |
||
519 | * @return self |
||
520 | */ |
||
521 | public function setCategories(array $categories) : self |
||
522 | { |
||
523 | $this->categories = $categories; |
||
524 | return $this; |
||
525 | } |
||
526 | /** |
||
527 | * A collection of meta data |
||
528 | * |
||
529 | * @return ProductMetaDataModelUpdatable[] |
||
530 | */ |
||
531 | public function getMetaData() : array |
||
534 | } |
||
535 | /** |
||
536 | * A collection of meta data |
||
537 | * |
||
538 | * @param ProductMetaDataModelUpdatable[] $metaData |
||
539 | * |
||
540 | * @return self |
||
541 | */ |
||
542 | public function setMetaData(array $metaData) : self |
||
546 | } |
||
547 | } |