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