| Total Complexity | 75 |
| Total Lines | 948 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like AbstractOffer 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 AbstractOffer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | abstract class AbstractOffer implements OfferInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $id; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var bool |
||
| 28 | */ |
||
| 29 | private $available; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $url; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var float |
||
| 38 | */ |
||
| 39 | private $price; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var float |
||
| 43 | */ |
||
| 44 | private $oldPrice; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var float |
||
| 48 | */ |
||
| 49 | private $purchasePrice; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $currencyId; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var int |
||
| 58 | */ |
||
| 59 | private $categoryId; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var array |
||
| 63 | */ |
||
| 64 | private $categoriesId = []; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $name; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | private $marketCategory; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var bool |
||
| 78 | */ |
||
| 79 | private $adult; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | private $salesNotes; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var bool |
||
| 88 | */ |
||
| 89 | private $manufacturerWarranty; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var bool |
||
| 93 | */ |
||
| 94 | private $pickup; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var bool |
||
| 98 | */ |
||
| 99 | private $downloadable; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @var bool |
||
| 103 | */ |
||
| 104 | private $delivery; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var float |
||
| 108 | */ |
||
| 109 | private $localDeliveryCost; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var array |
||
| 113 | */ |
||
| 114 | private $deliveryOptions = []; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var string |
||
| 118 | */ |
||
| 119 | private $description; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var string |
||
| 123 | */ |
||
| 124 | private $countryOfOrigin; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var string |
||
| 128 | */ |
||
| 129 | private $weight; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @var string |
||
| 133 | */ |
||
| 134 | private $dimensions; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var int |
||
| 138 | */ |
||
| 139 | private $cpa; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var string[] |
||
| 143 | */ |
||
| 144 | private $barcodes; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @var array |
||
| 148 | */ |
||
| 149 | private $pictures = []; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var array |
||
| 153 | */ |
||
| 154 | private $params = []; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @var array |
||
| 158 | */ |
||
| 159 | private $outlets = []; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @var bool |
||
| 163 | */ |
||
| 164 | private $store; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @var bool |
||
| 168 | */ |
||
| 169 | private $autoDiscount; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Array of custom elements (element types are keys) of arrays of element values |
||
| 173 | * There may be multiple elements of the same type |
||
| 174 | * |
||
| 175 | * @var array[] |
||
| 176 | */ |
||
| 177 | private $customElements; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @var OfferCondition |
||
| 181 | */ |
||
| 182 | private $condition; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return array |
||
| 186 | */ |
||
| 187 | public function toArray() |
||
| 188 | { |
||
| 189 | return \array_merge($this->getHeaderOptions(), $this->getOptions(), $this->getFooterOptions()); |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @return string |
||
| 194 | */ |
||
| 195 | public function getId() |
||
| 196 | { |
||
| 197 | return $this->id; |
||
| 198 | } |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @param string $id |
||
| 202 | * |
||
| 203 | * @return $this |
||
| 204 | */ |
||
| 205 | public function setId($id) |
||
| 206 | { |
||
| 207 | $this->id = $id; |
||
| 208 | |||
| 209 | return $this; |
||
| 210 | } |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return bool |
||
| 214 | */ |
||
| 215 | public function isAvailable() |
||
| 216 | { |
||
| 217 | return $this->available; |
||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param bool $available |
||
| 222 | * |
||
| 223 | * @return $this |
||
| 224 | */ |
||
| 225 | public function setAvailable($available) |
||
| 226 | { |
||
| 227 | $this->available = $available; |
||
| 228 | |||
| 229 | return $this; |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | public function getUrl() |
||
| 236 | { |
||
| 237 | return $this->url; |
||
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @param string $url |
||
| 242 | * |
||
| 243 | * @return $this |
||
| 244 | */ |
||
| 245 | public function setUrl($url) |
||
| 246 | { |
||
| 247 | $this->url = $url; |
||
| 248 | |||
| 249 | return $this; |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @return float |
||
| 254 | */ |
||
| 255 | public function getPrice() |
||
| 256 | { |
||
| 257 | return $this->price; |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @param float $price |
||
| 262 | * |
||
| 263 | * @return $this |
||
| 264 | */ |
||
| 265 | public function setPrice($price) |
||
| 266 | { |
||
| 267 | $this->price = $price; |
||
| 268 | |||
| 269 | return $this; |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @return float |
||
| 274 | */ |
||
| 275 | public function getOldPrice() |
||
| 276 | { |
||
| 277 | return $this->oldPrice; |
||
| 278 | } |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @param float $oldPrice |
||
| 282 | * |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | public function setOldPrice($oldPrice) |
||
| 286 | { |
||
| 287 | $this->oldPrice = $oldPrice; |
||
| 288 | |||
| 289 | return $this; |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @return float |
||
| 294 | */ |
||
| 295 | public function getPurchasePrice() |
||
| 296 | { |
||
| 297 | return $this->purchasePrice; |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param float $purchasePrice |
||
| 302 | * |
||
| 303 | * @return $this |
||
| 304 | */ |
||
| 305 | public function setPurchasePrice($purchasePrice) |
||
| 306 | { |
||
| 307 | $this->purchasePrice = $purchasePrice; |
||
| 308 | |||
| 309 | return $this; |
||
| 310 | } |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return string |
||
| 314 | */ |
||
| 315 | public function getCurrencyId() |
||
| 316 | { |
||
| 317 | return $this->currencyId; |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @param string $currencyId |
||
| 322 | * |
||
| 323 | * @return $this |
||
| 324 | */ |
||
| 325 | public function setCurrencyId($currencyId) |
||
| 326 | { |
||
| 327 | $this->currencyId = $currencyId; |
||
| 328 | |||
| 329 | return $this; |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return int |
||
| 334 | */ |
||
| 335 | public function getCategoryId() |
||
| 336 | { |
||
| 337 | return $this->categoryId; |
||
| 338 | } |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @param int $categoryId |
||
| 342 | * |
||
| 343 | * @return $this |
||
| 344 | */ |
||
| 345 | public function setCategoryId($categoryId) |
||
| 346 | { |
||
| 347 | $this->categoryId = $categoryId; |
||
| 348 | |||
| 349 | return $this; |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return array |
||
| 354 | */ |
||
| 355 | public function getCategoriesId() |
||
| 356 | { |
||
| 357 | return $this->categoriesId; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param array $categoriesId |
||
| 362 | * |
||
| 363 | * @return $this |
||
| 364 | */ |
||
| 365 | public function setCategoriesId(array $categoriesId) |
||
| 366 | { |
||
| 367 | $this->categoriesId = $categoriesId; |
||
| 368 | |||
| 369 | return $this; |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return string |
||
| 374 | */ |
||
| 375 | public function getName() |
||
| 376 | { |
||
| 377 | return $this->name; |
||
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @param string $name |
||
| 382 | * |
||
| 383 | * @return $this |
||
| 384 | */ |
||
| 385 | public function setName($name) |
||
| 386 | { |
||
| 387 | $this->name = $name; |
||
| 388 | |||
| 389 | return $this; |
||
| 390 | } |
||
| 391 | |||
| 392 | /** |
||
| 393 | * @return string |
||
| 394 | */ |
||
| 395 | public function getMarketCategory() |
||
| 396 | { |
||
| 397 | return $this->marketCategory; |
||
| 398 | } |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @param string $marketCategory |
||
| 402 | * |
||
| 403 | * @return $this |
||
| 404 | */ |
||
| 405 | public function setMarketCategory($marketCategory) |
||
| 406 | { |
||
| 407 | $this->marketCategory = $marketCategory; |
||
| 408 | |||
| 409 | return $this; |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @return bool |
||
| 414 | */ |
||
| 415 | public function isAdult() |
||
| 416 | { |
||
| 417 | return $this->adult; |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @param bool $adult |
||
| 422 | * |
||
| 423 | * @return $this |
||
| 424 | */ |
||
| 425 | public function setAdult($adult) |
||
| 426 | { |
||
| 427 | $this->adult = $adult; |
||
| 428 | |||
| 429 | return $this; |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return string |
||
| 434 | */ |
||
| 435 | public function getSalesNotes() |
||
| 436 | { |
||
| 437 | return $this->salesNotes; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * @param string $salesNotes |
||
| 442 | * |
||
| 443 | * @return $this |
||
| 444 | */ |
||
| 445 | public function setSalesNotes($salesNotes) |
||
| 446 | { |
||
| 447 | $this->salesNotes = $salesNotes; |
||
| 448 | |||
| 449 | return $this; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @return bool |
||
| 454 | */ |
||
| 455 | public function isManufacturerWarranty() |
||
| 456 | { |
||
| 457 | return $this->manufacturerWarranty; |
||
| 458 | } |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param bool $manufacturerWarranty |
||
| 462 | * |
||
| 463 | * @return $this |
||
| 464 | */ |
||
| 465 | public function setManufacturerWarranty($manufacturerWarranty) |
||
| 466 | { |
||
| 467 | $this->manufacturerWarranty = $manufacturerWarranty; |
||
| 468 | |||
| 469 | return $this; |
||
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @return bool |
||
| 474 | */ |
||
| 475 | public function isPickup() |
||
| 476 | { |
||
| 477 | return $this->pickup; |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @param bool $pickup |
||
| 482 | * |
||
| 483 | * @return $this |
||
| 484 | */ |
||
| 485 | public function setPickup($pickup) |
||
| 486 | { |
||
| 487 | $this->pickup = $pickup; |
||
| 488 | |||
| 489 | return $this; |
||
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * @return bool |
||
| 494 | */ |
||
| 495 | public function isDownloadable() |
||
| 496 | { |
||
| 497 | return $this->downloadable; |
||
| 498 | } |
||
| 499 | |||
| 500 | /** |
||
| 501 | * @param bool $downloadable |
||
| 502 | * |
||
| 503 | * @return $this |
||
| 504 | */ |
||
| 505 | public function setDownloadable($downloadable) |
||
| 506 | { |
||
| 507 | $this->downloadable = $downloadable; |
||
| 508 | |||
| 509 | return $this; |
||
| 510 | } |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @return bool |
||
| 514 | */ |
||
| 515 | public function isDelivery() |
||
| 516 | { |
||
| 517 | return $this->delivery; |
||
| 518 | } |
||
| 519 | |||
| 520 | /** |
||
| 521 | * @param bool $delivery |
||
| 522 | * |
||
| 523 | * @return $this |
||
| 524 | */ |
||
| 525 | public function setDelivery($delivery) |
||
| 526 | { |
||
| 527 | $this->delivery = $delivery; |
||
| 528 | |||
| 529 | return $this; |
||
| 530 | } |
||
| 531 | |||
| 532 | /** |
||
| 533 | * @return array |
||
| 534 | */ |
||
| 535 | public function getDeliveryOptions() |
||
| 536 | { |
||
| 537 | return $this->deliveryOptions; |
||
| 538 | } |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @param Delivery $option |
||
| 542 | * |
||
| 543 | * @return $this |
||
| 544 | */ |
||
| 545 | public function addDeliveryOption(Delivery $option) |
||
| 546 | { |
||
| 547 | $this->deliveryOptions[] = $option; |
||
| 548 | |||
| 549 | return $this; |
||
| 550 | } |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @param bool $store |
||
| 554 | * |
||
| 555 | * @return $this |
||
| 556 | */ |
||
| 557 | public function setStore($store) |
||
| 558 | { |
||
| 559 | $this->store = $store; |
||
| 560 | |||
| 561 | return $this; |
||
| 562 | } |
||
| 563 | |||
| 564 | /** |
||
| 565 | * @return bool |
||
| 566 | */ |
||
| 567 | public function isStore() |
||
| 568 | { |
||
| 569 | return $this->store; |
||
| 570 | } |
||
| 571 | |||
| 572 | /** |
||
| 573 | * @return float |
||
| 574 | */ |
||
| 575 | public function getLocalDeliveryCost() |
||
| 578 | } |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @param float $localDeliveryCost |
||
| 582 | * |
||
| 583 | * @return $this |
||
| 584 | */ |
||
| 585 | public function setLocalDeliveryCost($localDeliveryCost) |
||
| 586 | { |
||
| 587 | $this->localDeliveryCost = $localDeliveryCost; |
||
| 588 | |||
| 589 | return $this; |
||
| 590 | } |
||
| 591 | |||
| 592 | /** |
||
| 593 | * @return string |
||
| 594 | */ |
||
| 595 | public function getDescription() |
||
| 596 | { |
||
| 597 | return $this->description; |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * @param string $description |
||
| 602 | * |
||
| 603 | * @return $this |
||
| 604 | */ |
||
| 605 | public function setDescription($description) |
||
| 606 | { |
||
| 607 | $this->description = $description; |
||
| 608 | |||
| 609 | return $this; |
||
| 610 | } |
||
| 611 | |||
| 612 | /** |
||
| 613 | * @return string |
||
| 614 | */ |
||
| 615 | public function getCountryOfOrigin() |
||
| 616 | { |
||
| 617 | return $this->countryOfOrigin; |
||
| 618 | } |
||
| 619 | |||
| 620 | /** |
||
| 621 | * @param string $countryOfOrigin |
||
| 622 | * |
||
| 623 | * @return $this |
||
| 624 | */ |
||
| 625 | public function setCountryOfOrigin($countryOfOrigin) |
||
| 626 | { |
||
| 627 | $this->countryOfOrigin = $countryOfOrigin; |
||
| 628 | |||
| 629 | return $this; |
||
| 630 | } |
||
| 631 | |||
| 632 | /** |
||
| 633 | * @return string |
||
| 634 | */ |
||
| 635 | public function getWeight() |
||
| 636 | { |
||
| 637 | return $this->weight; |
||
| 638 | } |
||
| 639 | |||
| 640 | /** |
||
| 641 | * @param string $weight |
||
| 642 | * |
||
| 643 | * @return $this |
||
| 644 | */ |
||
| 645 | public function setWeight($weight) |
||
| 646 | { |
||
| 647 | $this->weight = $weight; |
||
| 648 | |||
| 649 | return $this; |
||
| 650 | } |
||
| 651 | |||
| 652 | /** |
||
| 653 | * @return string |
||
| 654 | */ |
||
| 655 | public function getDimensions() |
||
| 656 | { |
||
| 657 | return $this->dimensions; |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * @param float $length |
||
| 662 | * @param float $width |
||
| 663 | * @param float $height |
||
| 664 | * |
||
| 665 | * @return $this |
||
| 666 | */ |
||
| 667 | public function setDimensions($length, $width, $height) |
||
| 668 | { |
||
| 669 | $dimensions = [ |
||
| 670 | \round((float) $length, 3), |
||
| 671 | \round((float) $width, 3), |
||
| 672 | \round((float) $height, 3), |
||
| 673 | ]; |
||
| 674 | |||
| 675 | $this->dimensions = \implode('/', $dimensions); |
||
| 676 | |||
| 677 | return $this; |
||
| 678 | } |
||
| 679 | |||
| 680 | /** |
||
| 681 | * @return int |
||
| 682 | */ |
||
| 683 | public function getCpa() |
||
| 684 | { |
||
| 685 | return $this->cpa; |
||
| 686 | } |
||
| 687 | |||
| 688 | /** |
||
| 689 | * @param int $cpa |
||
| 690 | * |
||
| 691 | * @return $this |
||
| 692 | */ |
||
| 693 | public function setCpa($cpa) |
||
| 694 | { |
||
| 695 | $this->cpa = $cpa; |
||
| 696 | |||
| 697 | return $this; |
||
| 698 | } |
||
| 699 | |||
| 700 | /** |
||
| 701 | * @return array |
||
| 702 | */ |
||
| 703 | public function getParams() |
||
| 704 | { |
||
| 705 | return $this->params; |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * @param OfferParam $param |
||
| 710 | * |
||
| 711 | * @return $this |
||
| 712 | */ |
||
| 713 | public function addParam(OfferParam $param) |
||
| 714 | { |
||
| 715 | $this->params[] = $param; |
||
| 716 | |||
| 717 | return $this; |
||
| 718 | } |
||
| 719 | |||
| 720 | /** |
||
| 721 | * @return array |
||
| 722 | */ |
||
| 723 | public function getOutlets() |
||
| 724 | { |
||
| 725 | return $this->outlets; |
||
| 726 | } |
||
| 727 | |||
| 728 | /** |
||
| 729 | * @param OfferOutlet $outlet |
||
| 730 | * |
||
| 731 | * @return $this |
||
| 732 | */ |
||
| 733 | public function addOutlet(OfferOutlet $outlet) |
||
| 734 | { |
||
| 735 | $this->outlets[] = $outlet; |
||
| 736 | |||
| 737 | return $this; |
||
| 738 | } |
||
| 739 | |||
| 740 | /** |
||
| 741 | * Add picture |
||
| 742 | * |
||
| 743 | * @param string $url |
||
| 744 | * |
||
| 745 | * @return $this |
||
| 746 | */ |
||
| 747 | public function addPicture($url) |
||
| 748 | { |
||
| 749 | if (\count($this->pictures) < 10) { |
||
| 750 | $this->pictures[] = $url; |
||
| 751 | } |
||
| 752 | |||
| 753 | return $this; |
||
| 754 | } |
||
| 755 | |||
| 756 | /** |
||
| 757 | * Set pictures |
||
| 758 | * |
||
| 759 | * @param array $pictures |
||
| 760 | * |
||
| 761 | * @return $this |
||
| 762 | */ |
||
| 763 | public function setPictures(array $pictures) |
||
| 764 | { |
||
| 765 | $this->pictures = $pictures; |
||
| 766 | |||
| 767 | return $this; |
||
| 768 | } |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Get picture list |
||
| 772 | * |
||
| 773 | * @return array |
||
| 774 | */ |
||
| 775 | public function getPictures() |
||
| 776 | { |
||
| 777 | return $this->pictures; |
||
| 778 | } |
||
| 779 | |||
| 780 | /** |
||
| 781 | * Get list of barcodes of the offer |
||
| 782 | * |
||
| 783 | * @return string[] |
||
| 784 | */ |
||
| 785 | public function getBarcodes() |
||
| 786 | { |
||
| 787 | return $this->barcodes; |
||
| 788 | } |
||
| 789 | |||
| 790 | /** |
||
| 791 | * Set list of barcodes for that offer |
||
| 792 | * |
||
| 793 | * @param string[] $barcodes |
||
| 794 | * |
||
| 795 | * @return $this |
||
| 796 | */ |
||
| 797 | public function setBarcodes(array $barcodes = []) |
||
| 798 | { |
||
| 799 | $this->barcodes = $barcodes; |
||
| 800 | |||
| 801 | return $this; |
||
| 802 | } |
||
| 803 | |||
| 804 | /** |
||
| 805 | * Add one barcode to the collection of barcodes of this offer |
||
| 806 | * |
||
| 807 | * @param string $barcode |
||
| 808 | * |
||
| 809 | * @return $this |
||
| 810 | */ |
||
| 811 | public function addBarcode($barcode) |
||
| 812 | { |
||
| 813 | $this->barcodes[] = $barcode; |
||
| 814 | |||
| 815 | return $this; |
||
| 816 | } |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Sets list of custom elements |
||
| 820 | * |
||
| 821 | * @param array $customElements Array (keys are element types) of arrays (element values) |
||
| 822 | * |
||
| 823 | * @return $this |
||
| 824 | */ |
||
| 825 | public function setCustomElements(array $customElements = []) |
||
| 826 | { |
||
| 827 | $this->customElements = $customElements; |
||
| 828 | |||
| 829 | return $this; |
||
| 830 | } |
||
| 831 | |||
| 832 | /** |
||
| 833 | * Add a custom element with given type and value |
||
| 834 | * Multiple elements of the same type are supported |
||
| 835 | * |
||
| 836 | * @param string $elementType |
||
| 837 | * @param mixed $value |
||
| 838 | * |
||
| 839 | * @return $this |
||
| 840 | */ |
||
| 841 | public function addCustomElement($elementType, $value) |
||
| 842 | { |
||
| 843 | if ($value !== null) { |
||
| 844 | // Add value to the list of values of the given element type creating array when needed |
||
| 845 | $this->customElements[$elementType][] = $value; |
||
| 846 | } |
||
| 847 | |||
| 848 | return $this; |
||
| 849 | } |
||
| 850 | |||
| 851 | /** |
||
| 852 | * Returns a list of custom elements |
||
| 853 | * Always returns an array even if no custom elements were added |
||
| 854 | * |
||
| 855 | * @return array |
||
| 856 | */ |
||
| 857 | public function getCustomElements() |
||
| 858 | { |
||
| 859 | return $this->customElements ?: []; |
||
| 860 | } |
||
| 861 | |||
| 862 | /** |
||
| 863 | * Returns a list of values for the specified custom element type |
||
| 864 | * Always returns an array |
||
| 865 | * |
||
| 866 | * @param string $elementType |
||
| 867 | * |
||
| 868 | * @return array |
||
| 869 | */ |
||
| 870 | public function getCustomElementByType($elementType) |
||
| 871 | { |
||
| 872 | // TODO: Use ?? operator when support for PHP 5.6 is no longer needed |
||
| 873 | if (isset($this->customElements[$elementType])) { |
||
| 874 | return $this->customElements[$elementType]; |
||
| 875 | } |
||
| 876 | |||
| 877 | return []; |
||
| 878 | } |
||
| 879 | |||
| 880 | /** |
||
| 881 | * @return OfferCondition |
||
| 882 | */ |
||
| 883 | public function getCondition() |
||
| 884 | { |
||
| 885 | return $this->condition; |
||
| 886 | } |
||
| 887 | |||
| 888 | /** |
||
| 889 | * @param OfferCondition $condition |
||
| 890 | * |
||
| 891 | * @return $this |
||
| 892 | */ |
||
| 893 | public function addCondition(OfferCondition $condition) |
||
| 894 | { |
||
| 895 | $this->condition = $condition; |
||
| 896 | |||
| 897 | return $this; |
||
| 898 | } |
||
| 899 | |||
| 900 | /** |
||
| 901 | * @return bool |
||
| 902 | */ |
||
| 903 | public function getAutoDiscount() |
||
| 904 | { |
||
| 905 | return $this->autoDiscount; |
||
| 906 | } |
||
| 907 | |||
| 908 | /** |
||
| 909 | * @param bool $autoDiscount |
||
| 910 | * |
||
| 911 | * @return $this |
||
| 912 | */ |
||
| 913 | public function setAutoDiscount($autoDiscount) |
||
| 914 | { |
||
| 915 | $this->autoDiscount = $autoDiscount; |
||
| 916 | |||
| 917 | return $this; |
||
| 918 | } |
||
| 919 | |||
| 920 | /** |
||
| 921 | * @return array |
||
| 922 | */ |
||
| 923 | abstract protected function getOptions(); |
||
| 924 | |||
| 925 | /** |
||
| 926 | * @return array |
||
| 927 | */ |
||
| 928 | private function getHeaderOptions() |
||
| 951 | } |
||
| 952 | |||
| 953 | /** |
||
| 954 | * @return array |
||
| 955 | */ |
||
| 956 | private function getFooterOptions() |
||
| 957 | { |
||
| 958 | return [ |
||
| 959 | 'description' => $this->getDescription(), |
||
| 960 | 'sales_notes' => $this->getSalesNotes(), |
||
| 961 | 'manufacturer_warranty' => $this->isManufacturerWarranty(), |
||
| 962 | 'country_of_origin' => $this->getCountryOfOrigin(), |
||
| 963 | 'downloadable' => $this->isDownloadable(), |
||
| 964 | 'adult' => $this->isAdult(), |
||
| 965 | 'cpa' => $this->getCpa(), |
||
| 966 | 'barcode' => $this->getBarcodes(), |
||
| 967 | ]; |
||
| 968 | } |
||
| 969 | } |
||
| 970 |