| Total Complexity | 44 |
| Total Lines | 529 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Category 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 Category, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | class Category extends AbstractEntity implements CategoryInterface |
||
| 22 | { |
||
| 23 | use CategoryTrait; |
||
| 24 | use Timestampable; |
||
| 25 | use SoftDeletable; |
||
| 26 | use Translatable; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var int |
||
| 30 | * |
||
| 31 | * @ORM\Id |
||
| 32 | * @ORM\GeneratedValue |
||
| 33 | * @ORM\Column(type="integer") |
||
| 34 | **/ |
||
| 35 | protected $id; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * This is the internal id in the API |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | * |
||
| 42 | * @ORM\Column(type="integer", unique=true) |
||
| 43 | */ |
||
| 44 | protected $externalId; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | * |
||
| 49 | * @ORM\Column(type="string", unique=true) |
||
| 50 | */ |
||
| 51 | protected $number; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var string|null |
||
| 55 | * |
||
| 56 | * @ORM\Column(nullable=true, type="string", length=191) |
||
| 57 | */ |
||
| 58 | protected $b2bGroupId; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var \DateTimeImmutable|null |
||
| 62 | * |
||
| 63 | * @ORM\Column(nullable=true, type="datetime_immutable") |
||
| 64 | */ |
||
| 65 | protected $createdDate; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var int|null |
||
| 69 | * |
||
| 70 | * @ORM\Column(nullable=true, type="integer") |
||
| 71 | */ |
||
| 72 | protected $customInfoLayout; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var int|null |
||
| 76 | * |
||
| 77 | * @ORM\Column(nullable=true, type="integer") |
||
| 78 | */ |
||
| 79 | protected $customListLayout; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var int|null |
||
| 83 | * |
||
| 84 | * @ORM\Column(nullable=true, type="integer") |
||
| 85 | */ |
||
| 86 | protected $defaultParentId; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @var \DateTimeImmutable|null |
||
| 90 | * |
||
| 91 | * @ORM\Column(nullable=true, type="datetime_immutable") |
||
| 92 | */ |
||
| 93 | protected $editedDate; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var int|null |
||
| 97 | * |
||
| 98 | * @ORM\Column(nullable=true, type="integer") |
||
| 99 | */ |
||
| 100 | protected $infoLayout; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var int|null |
||
| 104 | * |
||
| 105 | * @ORM\Column(nullable=true, type="integer") |
||
| 106 | */ |
||
| 107 | protected $internalId; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var int|null |
||
| 111 | * |
||
| 112 | * @ORM\Column(nullable=true, type="integer") |
||
| 113 | */ |
||
| 114 | protected $listLayout; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @var bool|null |
||
| 118 | * |
||
| 119 | * @ORM\Column(nullable=true, type="boolean") |
||
| 120 | */ |
||
| 121 | protected $modified; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * The parent 'id' really refers to the parent number |
||
| 125 | * |
||
| 126 | * @var array|null |
||
| 127 | * |
||
| 128 | * @ORM\Column(nullable=true, type="json") |
||
| 129 | */ |
||
| 130 | protected $parentIdList; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var array|null |
||
| 134 | * |
||
| 135 | * @ORM\Column(nullable=true, type="json") |
||
| 136 | */ |
||
| 137 | protected $segmentIdList; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @var Category[]|ArrayCollection |
||
| 141 | * |
||
| 142 | * @ORM\ManyToMany(mappedBy="parentCategories", targetEntity="Category") |
||
| 143 | */ |
||
| 144 | protected $childrenCategories; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @var Category[]|ArrayCollection |
||
| 148 | * |
||
| 149 | * @ORM\JoinTable(name="ldf_category_parents") |
||
| 150 | * @ORM\ManyToMany(cascade={"persist"}, inversedBy="childrenCategories", targetEntity="Category") |
||
| 151 | */ |
||
| 152 | protected $parentCategories; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var Product[]||ArrayCollection |
||
| 156 | * |
||
| 157 | * @ORM\ManyToMany(mappedBy="categories", targetEntity="Product") |
||
| 158 | */ |
||
| 159 | protected $products; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @var Segment[]|ArrayCollection |
||
| 163 | * |
||
| 164 | * @ORM\JoinTable(name="ldf_category_segments") |
||
| 165 | * @ORM\ManyToMany(cascade={"persist"}, inversedBy="categories", targetEntity="Segment") |
||
| 166 | */ |
||
| 167 | protected $segments; |
||
| 168 | |||
| 169 | public function __construct() |
||
| 170 | { |
||
| 171 | $this->childrenCategories = new ArrayCollection(); |
||
| 172 | $this->parentCategories = new ArrayCollection(); |
||
| 173 | $this->products = new ArrayCollection(); |
||
| 174 | $this->segments = new ArrayCollection(); |
||
| 175 | } |
||
| 176 | |||
| 177 | /* |
||
| 178 | * Collection methods |
||
| 179 | */ |
||
| 180 | public function addParentCategory(CategoryInterface $category) : CategoryInterface |
||
| 181 | { |
||
| 182 | if(!$this->hasParentCategory($category)) { |
||
| 183 | $this->parentCategories->add($category); |
||
| 184 | } |
||
| 185 | |||
| 186 | return $this; |
||
| 187 | } |
||
| 188 | |||
| 189 | public function hasParentCategory($category) : bool |
||
| 197 | }); |
||
| 198 | } |
||
| 199 | |||
| 200 | public function removeParentCategory(CategoryInterface $category) : CategoryInterface |
||
| 201 | { |
||
| 202 | $this->parentCategories->removeElement($category); |
||
| 203 | |||
| 204 | return $this; |
||
| 205 | } |
||
| 206 | |||
| 207 | /* |
||
| 208 | * Getters / Setters |
||
| 209 | */ |
||
| 210 | /** |
||
| 211 | * @return int |
||
| 212 | */ |
||
| 213 | public function getId(): int |
||
| 214 | { |
||
| 215 | return (int)$this->id; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param int $id |
||
| 220 | * @return Category |
||
| 221 | */ |
||
| 222 | public function setId(int $id) |
||
| 223 | { |
||
| 224 | $this->id = $id; |
||
| 225 | return $this; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return int |
||
| 230 | */ |
||
| 231 | public function getExternalId(): int |
||
| 232 | { |
||
| 233 | return (int)$this->externalId; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param int $externalId |
||
| 238 | * @return Category |
||
| 239 | */ |
||
| 240 | public function setExternalId(int $externalId) |
||
| 241 | { |
||
| 242 | $this->externalId = $externalId; |
||
| 243 | return $this; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | public function getNumber(): string |
||
| 250 | { |
||
| 251 | return (string)$this->number; |
||
| 252 | } |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param string $number |
||
| 256 | * @return Category |
||
| 257 | */ |
||
| 258 | public function setNumber(string $number) |
||
| 259 | { |
||
| 260 | $this->number = $number; |
||
| 261 | return $this; |
||
| 262 | } |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @return null|string |
||
| 266 | */ |
||
| 267 | public function getB2bGroupId() |
||
| 268 | { |
||
| 269 | return $this->b2bGroupId; |
||
| 270 | } |
||
| 271 | |||
| 272 | /** |
||
| 273 | * @param null|string $b2bGroupId |
||
| 274 | * @return Category |
||
| 275 | */ |
||
| 276 | public function setB2bGroupId($b2bGroupId) |
||
| 277 | { |
||
| 278 | $this->b2bGroupId = $b2bGroupId; |
||
| 279 | return $this; |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return \DateTimeImmutable|null |
||
| 284 | */ |
||
| 285 | public function getCreatedDate() |
||
| 286 | { |
||
| 287 | return $this->createdDate; |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @param \DateTimeImmutable|null $createdDate |
||
| 292 | * @return Category |
||
| 293 | */ |
||
| 294 | public function setCreatedDate($createdDate) |
||
| 295 | { |
||
| 296 | $this->createdDate = $createdDate; |
||
| 297 | return $this; |
||
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return int|null |
||
| 302 | */ |
||
| 303 | public function getCustomInfoLayout() |
||
| 304 | { |
||
| 305 | return $this->customInfoLayout; |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param int|null $customInfoLayout |
||
| 310 | * @return Category |
||
| 311 | */ |
||
| 312 | public function setCustomInfoLayout($customInfoLayout) |
||
| 313 | { |
||
| 314 | $this->customInfoLayout = $customInfoLayout; |
||
| 315 | return $this; |
||
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @return int|null |
||
| 320 | */ |
||
| 321 | public function getCustomListLayout() |
||
| 322 | { |
||
| 323 | return $this->customListLayout; |
||
| 324 | } |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @param int|null $customListLayout |
||
| 328 | * @return Category |
||
| 329 | */ |
||
| 330 | public function setCustomListLayout($customListLayout) |
||
| 331 | { |
||
| 332 | $this->customListLayout = $customListLayout; |
||
| 333 | return $this; |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @return int|null |
||
| 338 | */ |
||
| 339 | public function getDefaultParentId() |
||
| 340 | { |
||
| 341 | return $this->defaultParentId; |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @param int|null $defaultParentId |
||
| 346 | * @return Category |
||
| 347 | */ |
||
| 348 | public function setDefaultParentId($defaultParentId) |
||
| 349 | { |
||
| 350 | $this->defaultParentId = $defaultParentId; |
||
| 351 | return $this; |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return \DateTimeImmutable|null |
||
| 356 | */ |
||
| 357 | public function getEditedDate() |
||
| 358 | { |
||
| 359 | return $this->editedDate; |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param \DateTimeImmutable|null $editedDate |
||
| 364 | * @return Category |
||
| 365 | */ |
||
| 366 | public function setEditedDate($editedDate) |
||
| 367 | { |
||
| 368 | $this->editedDate = $editedDate; |
||
| 369 | return $this; |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return int|null |
||
| 374 | */ |
||
| 375 | public function getInfoLayout() |
||
| 376 | { |
||
| 377 | return $this->infoLayout; |
||
| 378 | } |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @param int|null $infoLayout |
||
| 382 | * @return Category |
||
| 383 | */ |
||
| 384 | public function setInfoLayout($infoLayout) |
||
| 385 | { |
||
| 386 | $this->infoLayout = $infoLayout; |
||
| 387 | return $this; |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return int|null |
||
| 392 | */ |
||
| 393 | public function getInternalId() |
||
| 396 | } |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param int|null $internalId |
||
| 400 | * @return Category |
||
| 401 | */ |
||
| 402 | public function setInternalId($internalId) |
||
| 403 | { |
||
| 404 | $this->internalId = $internalId; |
||
| 405 | return $this; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @return int|null |
||
| 410 | */ |
||
| 411 | public function getListLayout() |
||
| 412 | { |
||
| 413 | return $this->listLayout; |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @param int|null $listLayout |
||
| 418 | * @return Category |
||
| 419 | */ |
||
| 420 | public function setListLayout($listLayout) |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @return bool|null |
||
| 428 | */ |
||
| 429 | public function getModified() |
||
| 430 | { |
||
| 431 | return $this->modified; |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @param bool|null $modified |
||
| 436 | * @return Category |
||
| 437 | */ |
||
| 438 | public function setModified($modified) |
||
| 439 | { |
||
| 440 | $this->modified = $modified; |
||
| 441 | return $this; |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @return array|null |
||
| 446 | */ |
||
| 447 | public function getParentIdList() |
||
| 448 | { |
||
| 449 | return $this->parentIdList; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @param array|null $parentIdList |
||
| 454 | * @return Category |
||
| 455 | */ |
||
| 456 | public function setParentIdList($parentIdList) |
||
| 457 | { |
||
| 458 | $this->parentIdList = $parentIdList; |
||
| 459 | return $this; |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @return array|null |
||
| 464 | */ |
||
| 465 | public function getSegmentIdList() |
||
| 466 | { |
||
| 467 | return $this->segmentIdList; |
||
| 468 | } |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @param array|null $segmentIdList |
||
| 472 | * @return Category |
||
| 473 | */ |
||
| 474 | public function setSegmentIdList($segmentIdList) |
||
| 475 | { |
||
| 476 | $this->segmentIdList = $segmentIdList; |
||
| 477 | return $this; |
||
| 478 | } |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @return ArrayCollection|Category[] |
||
| 482 | */ |
||
| 483 | public function getChildrenCategories() |
||
| 484 | { |
||
| 485 | return $this->childrenCategories; |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @param ArrayCollection|Category[] $childrenCategories |
||
| 490 | * @return Category |
||
| 491 | */ |
||
| 492 | public function setChildrenCategories($childrenCategories) |
||
| 493 | { |
||
| 494 | $this->childrenCategories = $childrenCategories; |
||
| 495 | return $this; |
||
| 496 | } |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @return ArrayCollection|Category[] |
||
| 500 | */ |
||
| 501 | public function getParentCategories() |
||
| 502 | { |
||
| 503 | return $this->parentCategories; |
||
| 504 | } |
||
| 505 | |||
| 506 | /** |
||
| 507 | * @param ArrayCollection|Category[] $parentCategories |
||
| 508 | * @return Category |
||
| 509 | */ |
||
| 510 | public function setParentCategories($parentCategories) |
||
| 511 | { |
||
| 512 | $this->parentCategories = $parentCategories; |
||
| 513 | return $this; |
||
| 514 | } |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @return Product[] |
||
| 518 | */ |
||
| 519 | public function getProducts(): array |
||
| 522 | } |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param Product[] $products |
||
| 526 | * @return Category |
||
| 527 | */ |
||
| 528 | public function setProducts(array $products) |
||
| 529 | { |
||
| 530 | $this->products = $products; |
||
| 531 | return $this; |
||
| 532 | } |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @return ArrayCollection|Segment[] |
||
| 536 | */ |
||
| 537 | public function getSegments() |
||
| 538 | { |
||
| 539 | return $this->segments; |
||
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * @param ArrayCollection|Segment[] $segments |
||
| 544 | * @return Category |
||
| 545 | */ |
||
| 546 | public function setSegments($segments) |
||
| 550 | } |
||
| 551 | } |
||
| 552 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths