Complex classes like ArticleDetail 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 ArticleDetail, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class ArticleDetail extends Base |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var int |
||
| 19 | */ |
||
| 20 | protected $id; |
||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $number; |
||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $supplierNumber; |
||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $additionalText; |
||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $weight; |
||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $width; |
||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $len; |
||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $height; |
||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | protected $ean; |
||
| 53 | /** |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $purchaseUnit; |
||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $descriptionLong; |
||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $referenceUnit; |
||
| 65 | /** |
||
| 66 | * @var string |
||
| 67 | */ |
||
| 68 | protected $packUnit; |
||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | protected $shippingTime; |
||
| 73 | /** |
||
| 74 | * @var Price[] |
||
| 75 | */ |
||
| 76 | protected $prices; |
||
| 77 | /** |
||
| 78 | * @var ConfiguratorOption[] |
||
| 79 | */ |
||
| 80 | protected $configuratorOptions; |
||
| 81 | /** |
||
| 82 | * @var ArticleAttribute |
||
| 83 | */ |
||
| 84 | protected $attribute; |
||
| 85 | /** |
||
| 86 | * @var int |
||
| 87 | */ |
||
| 88 | protected $articleId; |
||
| 89 | /** |
||
| 90 | * @var int |
||
| 91 | */ |
||
| 92 | protected $unitId; |
||
| 93 | /** |
||
| 94 | * @var int |
||
| 95 | */ |
||
| 96 | protected $kind; |
||
| 97 | /** |
||
| 98 | * @var int |
||
| 99 | */ |
||
| 100 | protected $inStock; |
||
| 101 | /** |
||
| 102 | * @var int |
||
| 103 | */ |
||
| 104 | protected $position; |
||
| 105 | /** |
||
| 106 | * @var int |
||
| 107 | */ |
||
| 108 | protected $minPurchase; |
||
| 109 | /** |
||
| 110 | * @var int |
||
| 111 | */ |
||
| 112 | protected $purchaseSteps; |
||
| 113 | /** |
||
| 114 | * @var int |
||
| 115 | */ |
||
| 116 | protected $maxPurchase; |
||
| 117 | /** |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | protected $releaseDate; |
||
| 121 | /** |
||
| 122 | * @var bool |
||
| 123 | */ |
||
| 124 | protected $active; |
||
| 125 | /** |
||
| 126 | * @var bool |
||
| 127 | */ |
||
| 128 | protected $shippingFree; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return int |
||
| 132 | */ |
||
| 133 | public function getId() |
||
| 134 | { |
||
| 135 | return $this->id; |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param int $id |
||
| 140 | * |
||
| 141 | * @return ArticleDetail |
||
| 142 | */ |
||
| 143 | public function setId($id) |
||
| 144 | { |
||
| 145 | $this->id = $id; |
||
| 146 | |||
| 147 | return $this; |
||
| 148 | } |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return string |
||
| 152 | */ |
||
| 153 | public function getNumber() |
||
| 154 | { |
||
| 155 | return $this->number; |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param string $number |
||
| 160 | * |
||
| 161 | * @return ArticleDetail |
||
| 162 | */ |
||
| 163 | public function setNumber($number) |
||
| 164 | { |
||
| 165 | $this->number = $number; |
||
| 166 | |||
| 167 | return $this; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return string |
||
| 172 | */ |
||
| 173 | public function getSupplierNumber() |
||
| 174 | { |
||
| 175 | return $this->supplierNumber; |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @param string $supplierNumber |
||
| 180 | * |
||
| 181 | * @return ArticleDetail |
||
| 182 | */ |
||
| 183 | public function setSupplierNumber($supplierNumber) |
||
| 184 | { |
||
| 185 | $this->supplierNumber = $supplierNumber; |
||
| 186 | |||
| 187 | return $this; |
||
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return string |
||
| 192 | */ |
||
| 193 | public function getAdditionalText() |
||
| 194 | { |
||
| 195 | return $this->additionalText; |
||
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param string $additionalText |
||
| 200 | * |
||
| 201 | * @return ArticleDetail |
||
| 202 | */ |
||
| 203 | public function setAdditionalText($additionalText) |
||
| 204 | { |
||
| 205 | $this->additionalText = $additionalText; |
||
| 206 | |||
| 207 | return $this; |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | public function getWeight() |
||
| 214 | { |
||
| 215 | return $this->weight; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param string $weight |
||
| 220 | * |
||
| 221 | * @return ArticleDetail |
||
| 222 | */ |
||
| 223 | public function setWeight($weight) |
||
| 224 | { |
||
| 225 | $this->weight = $weight; |
||
| 226 | |||
| 227 | return $this; |
||
| 228 | } |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return string |
||
| 232 | */ |
||
| 233 | public function getWidth() |
||
| 234 | { |
||
| 235 | return $this->width; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param string $width |
||
| 240 | * |
||
| 241 | * @return ArticleDetail |
||
| 242 | */ |
||
| 243 | public function setWidth($width) |
||
| 244 | { |
||
| 245 | $this->width = $width; |
||
| 246 | |||
| 247 | return $this; |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | public function getLen() |
||
| 254 | { |
||
| 255 | return $this->len; |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @param string $len |
||
| 260 | * |
||
| 261 | * @return ArticleDetail |
||
| 262 | */ |
||
| 263 | public function setLen($len) |
||
| 264 | { |
||
| 265 | $this->len = $len; |
||
| 266 | |||
| 267 | return $this; |
||
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return string |
||
| 272 | */ |
||
| 273 | public function getHeight() |
||
| 274 | { |
||
| 275 | return $this->height; |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param string $height |
||
| 280 | * |
||
| 281 | * @return ArticleDetail |
||
| 282 | */ |
||
| 283 | public function setHeight($height) |
||
| 284 | { |
||
| 285 | $this->height = $height; |
||
| 286 | |||
| 287 | return $this; |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return string |
||
| 292 | */ |
||
| 293 | public function getEan() |
||
| 294 | { |
||
| 295 | return $this->ean; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param string $ean |
||
| 300 | * |
||
| 301 | * @return ArticleDetail |
||
| 302 | */ |
||
| 303 | public function setEan($ean) |
||
| 304 | { |
||
| 305 | $this->ean = $ean; |
||
| 306 | |||
| 307 | return $this; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return string |
||
| 312 | */ |
||
| 313 | public function getPurchaseUnit() |
||
| 314 | { |
||
| 315 | return $this->purchaseUnit; |
||
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param string $purchaseUnit |
||
| 320 | * |
||
| 321 | * @return ArticleDetail |
||
| 322 | */ |
||
| 323 | public function setPurchaseUnit($purchaseUnit) |
||
| 324 | { |
||
| 325 | $this->purchaseUnit = $purchaseUnit; |
||
| 326 | |||
| 327 | return $this; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getDescriptionLong() |
||
| 334 | { |
||
| 335 | return $this->descriptionLong; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $descriptionLong |
||
| 340 | * |
||
| 341 | * @return ArticleDetail |
||
| 342 | */ |
||
| 343 | public function setDescriptionLong($descriptionLong) |
||
| 344 | { |
||
| 345 | $this->descriptionLong = $descriptionLong; |
||
| 346 | |||
| 347 | return $this; |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @return string |
||
| 352 | */ |
||
| 353 | public function getReferenceUnit() |
||
| 354 | { |
||
| 355 | return $this->referenceUnit; |
||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @param string $referenceUnit |
||
| 360 | * |
||
| 361 | * @return ArticleDetail |
||
| 362 | */ |
||
| 363 | public function setReferenceUnit($referenceUnit) |
||
| 364 | { |
||
| 365 | $this->referenceUnit = $referenceUnit; |
||
| 366 | |||
| 367 | return $this; |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @return string |
||
| 372 | */ |
||
| 373 | public function getPackUnit() |
||
| 374 | { |
||
| 375 | return $this->packUnit; |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param string $packUnit |
||
| 380 | * |
||
| 381 | * @return ArticleDetail |
||
| 382 | */ |
||
| 383 | public function setPackUnit($packUnit) |
||
| 384 | { |
||
| 385 | $this->packUnit = $packUnit; |
||
| 386 | |||
| 387 | return $this; |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return string |
||
| 392 | */ |
||
| 393 | public function getShippingTime() |
||
| 394 | { |
||
| 395 | return $this->shippingTime; |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param string $shippingTime |
||
| 400 | * |
||
| 401 | * @return ArticleDetail |
||
| 402 | */ |
||
| 403 | public function setShippingTime($shippingTime) |
||
| 404 | { |
||
| 405 | $this->shippingTime = $shippingTime; |
||
| 406 | |||
| 407 | return $this; |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return Price[] |
||
| 412 | */ |
||
| 413 | public function getPrices() |
||
| 414 | { |
||
| 415 | return $this->prices; |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param Price[] $prices |
||
| 420 | * |
||
| 421 | * @return ArticleDetail |
||
| 422 | */ |
||
| 423 | public function setPrices($prices) |
||
| 424 | { |
||
| 425 | $this->prices = $prices; |
||
| 426 | |||
| 427 | return $this; |
||
| 428 | } |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @return ConfiguratorOption[] |
||
| 432 | */ |
||
| 433 | public function getConfiguratorOptions() |
||
| 434 | { |
||
| 435 | return $this->configuratorOptions; |
||
| 436 | } |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @param ConfiguratorOption[] $configuratorOptions |
||
| 440 | * |
||
| 441 | * @return ArticleDetail |
||
| 442 | */ |
||
| 443 | public function setConfiguratorOptions($configuratorOptions) |
||
| 444 | { |
||
| 445 | $this->configuratorOptions = $configuratorOptions; |
||
| 446 | |||
| 447 | return $this; |
||
| 448 | } |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return ArticleAttribute |
||
| 452 | */ |
||
| 453 | public function getAttributes() |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @param ArticleAttribute $attribute |
||
| 460 | * |
||
| 461 | * @return ArticleDetail |
||
| 462 | */ |
||
| 463 | public function setAttributes($attribute) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @return int |
||
| 472 | */ |
||
| 473 | public function getArticleId() |
||
| 474 | { |
||
| 475 | return $this->articleId; |
||
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * @param int $articleId |
||
| 480 | * |
||
| 481 | * @return ArticleDetail |
||
| 482 | */ |
||
| 483 | public function setArticleId($articleId) |
||
| 484 | { |
||
| 485 | $this->articleId = $articleId; |
||
| 486 | |||
| 487 | return $this; |
||
| 488 | } |
||
| 489 | |||
| 490 | /** |
||
| 491 | * @return int |
||
| 492 | */ |
||
| 493 | public function getUnitId() |
||
| 494 | { |
||
| 495 | return $this->unitId; |
||
| 496 | } |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @param int $unitId |
||
| 500 | * |
||
| 501 | * @return ArticleDetail |
||
| 502 | */ |
||
| 503 | public function setUnitId($unitId) |
||
| 504 | { |
||
| 509 | |||
| 510 | /** |
||
| 511 | * @return int |
||
| 512 | */ |
||
| 513 | public function getKind() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @param int $kind |
||
| 520 | * |
||
| 521 | * @return ArticleDetail |
||
| 522 | */ |
||
| 523 | public function setKind($kind) |
||
| 529 | |||
| 530 | /** |
||
| 531 | * @return int |
||
| 532 | */ |
||
| 533 | public function getInStock() |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @param int $inStock |
||
| 540 | * |
||
| 541 | * @return ArticleDetail |
||
| 542 | */ |
||
| 543 | public function setInStock($inStock) |
||
| 549 | |||
| 550 | /** |
||
| 551 | * @return int |
||
| 552 | */ |
||
| 553 | public function getPosition() |
||
| 557 | |||
| 558 | /** |
||
| 559 | * @param int $position |
||
| 560 | * |
||
| 561 | * @return ArticleDetail |
||
| 562 | */ |
||
| 563 | public function setPosition($position) |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @return int |
||
| 572 | */ |
||
| 573 | public function getMinPurchase() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * @param int $minPurchase |
||
| 580 | * |
||
| 581 | * @return ArticleDetail |
||
| 582 | */ |
||
| 583 | public function setMinPurchase($minPurchase) |
||
| 589 | |||
| 590 | /** |
||
| 591 | * @return int |
||
| 592 | */ |
||
| 593 | public function getPurchaseSteps() |
||
| 597 | |||
| 598 | /** |
||
| 599 | * @param int $purchaseSteps |
||
| 600 | * |
||
| 601 | * @return ArticleDetail |
||
| 602 | */ |
||
| 603 | public function setPurchaseSteps($purchaseSteps) |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @return int |
||
| 612 | */ |
||
| 613 | public function getMaxPurchase() |
||
| 617 | |||
| 618 | /** |
||
| 619 | * @param int $maxPurchase |
||
| 620 | * |
||
| 621 | * @return ArticleDetail |
||
| 622 | */ |
||
| 623 | public function setMaxPurchase($maxPurchase) |
||
| 629 | |||
| 630 | /** |
||
| 631 | * @return string |
||
| 632 | */ |
||
| 633 | public function getReleaseDate() |
||
| 637 | |||
| 638 | /** |
||
| 639 | * @param string $releaseDate |
||
| 640 | * |
||
| 641 | * @return ArticleDetail |
||
| 642 | */ |
||
| 643 | public function setReleaseDate($releaseDate) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @return bool |
||
| 652 | */ |
||
| 653 | public function isActive() |
||
| 657 | |||
| 658 | /** |
||
| 659 | * @param bool $active |
||
| 660 | * |
||
| 661 | * @return ArticleDetail |
||
| 662 | */ |
||
| 663 | public function setActive($active) |
||
| 669 | |||
| 670 | /** |
||
| 671 | * @return bool |
||
| 672 | */ |
||
| 673 | public function isShippingFree() |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @param bool $shippingFree |
||
| 680 | * |
||
| 681 | * @return ArticleDetail |
||
| 682 | */ |
||
| 683 | public function setShippingFree($shippingFree) |
||
| 689 | } |
||
| 690 |