Complex classes like View 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 View, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | abstract class View |
||
|
|
|||
| 31 | { |
||
| 32 | use \Gedmo\Timestampable\Traits\TimestampableEntity; |
||
| 33 | use Translatable; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @Serializer\Groups({"search"}) |
||
| 37 | */ |
||
| 38 | protected $translations; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var int |
||
| 42 | * |
||
| 43 | * @ORM\Column(name="id", type="integer") |
||
| 44 | * @ORM\Id |
||
| 45 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 46 | */ |
||
| 47 | protected $id; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | * |
||
| 52 | * @ORM\Column(name="bodyId", type="string", length=255, nullable=true) |
||
| 53 | */ |
||
| 54 | protected $bodyId; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | * |
||
| 59 | * @ORM\Column(name="bodyClass", type="string", length=255, nullable=true) |
||
| 60 | */ |
||
| 61 | protected $bodyClass; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var [WidgetMap] |
||
| 65 | * |
||
| 66 | * @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap", mappedBy="view", orphanRemoval=true, cascade={"persist", "remove"}) |
||
| 67 | */ |
||
| 68 | protected $widgetMaps = []; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @Gedmo\TreeParent |
||
| 72 | * @ORM\ManyToOne(targetEntity="View", inversedBy="children", cascade={"persist"}) |
||
| 73 | * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 74 | */ |
||
| 75 | protected $parent; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var int |
||
| 79 | * |
||
| 80 | * @ORM\Column(name="position", type="integer", nullable=false) |
||
| 81 | */ |
||
| 82 | protected $position = 0; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @Gedmo\TreeLeft |
||
| 86 | * @ORM\Column(name="lft", type="integer") |
||
| 87 | */ |
||
| 88 | protected $lft; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @Gedmo\TreeLevel |
||
| 92 | * @ORM\Column(name="lvl", type="integer") |
||
| 93 | */ |
||
| 94 | protected $lvl; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @Gedmo\TreeRight |
||
| 98 | * @ORM\Column(name="rgt", type="integer") |
||
| 99 | */ |
||
| 100 | protected $rgt; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @Gedmo\TreeRoot |
||
| 104 | * @ORM\Column(name="root", type="integer", nullable=true) |
||
| 105 | */ |
||
| 106 | protected $root; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @ORM\OneToMany(targetEntity="View", mappedBy="parent", cascade={"remove", "persist"}) |
||
| 110 | * @ORM\OrderBy({"lft" = "ASC"}) |
||
| 111 | */ |
||
| 112 | protected $children = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * This relation is dynamicly added by PageSubscriber. |
||
| 116 | */ |
||
| 117 | protected $author; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var string |
||
| 121 | * |
||
| 122 | * @ORM\Column(name="undeletable", type="boolean") |
||
| 123 | */ |
||
| 124 | protected $undeletable = false; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @var ViewReference[] |
||
| 128 | * The reference is related to viewsReferences.xml file which list all app views. |
||
| 129 | * This is used to speed up the routing system and identify virtual pages (BusinessPage). |
||
| 130 | */ |
||
| 131 | protected $references; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @var string |
||
| 135 | * |
||
| 136 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\TemplateBundle\Entity\Template", inversedBy="inheritors", cascade={"persist"}) |
||
| 137 | * @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE") |
||
| 138 | */ |
||
| 139 | protected $template; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var string |
||
| 143 | * |
||
| 144 | * @ORM\Column(name="cssHash", type="string", length=40 ,nullable=true) |
||
| 145 | */ |
||
| 146 | protected $cssHash; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @deprecated |
||
| 150 | * @ORM\Column(name="widget_map", type="array") |
||
| 151 | */ |
||
| 152 | protected $widgetMap = []; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @var string |
||
| 156 | * |
||
| 157 | * @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetBundle\Entity\Widget", mappedBy="view", cascade={"persist", "remove"}) |
||
| 158 | * @ORM\OrderBy({"id" = "ASC"}) |
||
| 159 | */ |
||
| 160 | protected $widgets; |
||
| 161 | /** |
||
| 162 | * @var bool |
||
| 163 | * |
||
| 164 | * @ORM\Column(name="cssUpToDate", type="boolean") |
||
| 165 | */ |
||
| 166 | protected $cssUpToDate = false; |
||
| 167 | /** |
||
| 168 | * @var bool |
||
| 169 | * |
||
| 170 | * @ORM\Column(name="roles", type="text", nullable=true) |
||
| 171 | */ |
||
| 172 | protected $roles; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @var array |
||
| 176 | */ |
||
| 177 | protected $builtWidgetMap; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Construct. |
||
| 181 | **/ |
||
| 182 | public function __construct() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * to string. |
||
| 191 | * |
||
| 192 | * @return string |
||
| 193 | **/ |
||
| 194 | public function __toString() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Get id. |
||
| 201 | * |
||
| 202 | * @return int |
||
| 203 | */ |
||
| 204 | public function getId() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Set id. |
||
| 211 | * |
||
| 212 | * @param id $id |
||
| 213 | */ |
||
| 214 | public function setId($id) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Set template. |
||
| 221 | * |
||
| 222 | * @param View $template |
||
| 223 | * |
||
| 224 | * @return View |
||
| 225 | */ |
||
| 226 | public function setTemplate($template) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Get template. |
||
| 235 | * |
||
| 236 | * @return View |
||
| 237 | */ |
||
| 238 | public function getTemplate() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Set parent. |
||
| 245 | * |
||
| 246 | * @param View $parent |
||
| 247 | */ |
||
| 248 | public function setParent(View $parent = null) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Get parent. |
||
| 258 | * |
||
| 259 | * @return View parent |
||
| 260 | */ |
||
| 261 | public function getParent() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Set children. |
||
| 268 | * |
||
| 269 | * @param View[] $children |
||
| 270 | * |
||
| 271 | * @return View |
||
| 272 | */ |
||
| 273 | public function setChildren($children) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Get children. |
||
| 287 | * |
||
| 288 | * @return View[] |
||
| 289 | */ |
||
| 290 | public function getChildren() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * Has children. |
||
| 297 | * |
||
| 298 | * @return int |
||
| 299 | */ |
||
| 300 | public function hasChildren() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Add child. |
||
| 307 | * |
||
| 308 | * @param View $child |
||
| 309 | */ |
||
| 310 | public function addChild(View $child) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Remove child. |
||
| 317 | * |
||
| 318 | * @param View $child |
||
| 319 | */ |
||
| 320 | public function removeChild(View $child) |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Get the left value. |
||
| 327 | * |
||
| 328 | * @return int |
||
| 329 | */ |
||
| 330 | public function getLft() |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Set the left value. |
||
| 337 | * |
||
| 338 | * @param int $lft |
||
| 339 | */ |
||
| 340 | public function setLft($lft) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Get the right value. |
||
| 347 | * |
||
| 348 | * @return int |
||
| 349 | */ |
||
| 350 | public function getRgt() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Set the right value. |
||
| 357 | * |
||
| 358 | * @param int $rgt |
||
| 359 | */ |
||
| 360 | public function setRgt($rgt) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Get the level value. |
||
| 367 | * |
||
| 368 | * @return int |
||
| 369 | */ |
||
| 370 | public function getLvl() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Set the level value. |
||
| 377 | * |
||
| 378 | * @param int $lvl |
||
| 379 | */ |
||
| 380 | public function setLvl($lvl) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Get the root value. |
||
| 387 | * |
||
| 388 | * @return int |
||
| 389 | */ |
||
| 390 | public function getRoot() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Set the root value. |
||
| 397 | * |
||
| 398 | * @param int $root |
||
| 399 | */ |
||
| 400 | public function setRoot($root) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Set undeletable. |
||
| 407 | * |
||
| 408 | * @param bool $undeletable |
||
| 409 | * |
||
| 410 | * @return View The current instance |
||
| 411 | */ |
||
| 412 | public function setUndeletable($undeletable) |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Is the widget is undeletable. |
||
| 421 | * |
||
| 422 | * @return string |
||
| 423 | */ |
||
| 424 | public function isUndeletable() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Get author. |
||
| 431 | * |
||
| 432 | * @return string |
||
| 433 | */ |
||
| 434 | public function getAuthor() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Set author. |
||
| 441 | * |
||
| 442 | * @param string $author |
||
| 443 | * |
||
| 444 | * @return $this |
||
| 445 | */ |
||
| 446 | public function setAuthor($author) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * Get bodyId. |
||
| 455 | * |
||
| 456 | * @return string |
||
| 457 | */ |
||
| 458 | public function getBodyId() |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Set bodyId. |
||
| 465 | * |
||
| 466 | * @param string $bodyId |
||
| 467 | * |
||
| 468 | * @return $this |
||
| 469 | */ |
||
| 470 | public function setBodyId($bodyId) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Get bodyClass. |
||
| 479 | * |
||
| 480 | * @return string |
||
| 481 | */ |
||
| 482 | public function getBodyClass() |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Set bodyClass. |
||
| 489 | * |
||
| 490 | * @param string $bodyClass |
||
| 491 | * |
||
| 492 | * @return $this |
||
| 493 | */ |
||
| 494 | public function setBodyClass($bodyClass) |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Set widgets. |
||
| 503 | * |
||
| 504 | * @param [WidgetMap] $widgetMaps |
||
| 505 | * |
||
| 506 | * @return View |
||
| 507 | */ |
||
| 508 | public function setWidgetMaps($widgetMaps) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get WidgetMaps. |
||
| 517 | * |
||
| 518 | * @return WidgetMap[] |
||
| 519 | */ |
||
| 520 | public function getWidgetMaps() |
||
| 524 | |||
| 525 | /** |
||
| 526 | * Add WidgetMap. |
||
| 527 | * |
||
| 528 | * @param WidgetMap $widgetMap |
||
| 529 | */ |
||
| 530 | public function addWidgetMap(WidgetMap $widgetMap) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Remove a widgetMap. |
||
| 540 | * |
||
| 541 | * @param WidgetMap $widgetMap |
||
| 542 | */ |
||
| 543 | public function removeWidgetMap(WidgetMap $widgetMap) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Get WidgetMaps for View and its Templates. |
||
| 550 | * |
||
| 551 | * @return WidgetMap[] |
||
| 552 | */ |
||
| 553 | public function getWidgetMapsForViewAndTemplates() |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Get builtWidgetMap. |
||
| 571 | * |
||
| 572 | * @return array |
||
| 573 | */ |
||
| 574 | public function getBuiltWidgetMap() |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Set builtWidgetMap. |
||
| 581 | * |
||
| 582 | * @param array $builtWidgetMap |
||
| 583 | * |
||
| 584 | * @return $this |
||
| 585 | */ |
||
| 586 | public function setBuiltWidgetMap($builtWidgetMap) |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Get discriminator type. |
||
| 595 | * |
||
| 596 | * @return int |
||
| 597 | */ |
||
| 598 | public function getType() |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Set position. |
||
| 607 | * |
||
| 608 | * @param int $position |
||
| 609 | */ |
||
| 610 | public function setPosition($position) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Get position. |
||
| 617 | * |
||
| 618 | * @return int |
||
| 619 | */ |
||
| 620 | public function getPosition() |
||
| 624 | |||
| 625 | /** |
||
| 626 | * Get reference according to the current locale. |
||
| 627 | * |
||
| 628 | * @param string $locale |
||
| 629 | * |
||
| 630 | * @return null|ViewReference |
||
| 631 | */ |
||
| 632 | public function getReference($locale = null) |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Get references. |
||
| 643 | * |
||
| 644 | * @return ViewReference[] |
||
| 645 | */ |
||
| 646 | public function getReferences() |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Set references. |
||
| 653 | * |
||
| 654 | * @param ViewReference[] $references |
||
| 655 | * |
||
| 656 | * @return $this |
||
| 657 | */ |
||
| 658 | public function setReferences($references) |
||
| 664 | |||
| 665 | /** |
||
| 666 | * Set reference. |
||
| 667 | * |
||
| 668 | * @param ViewReference $reference |
||
| 669 | * @param string $locale |
||
| 670 | * |
||
| 671 | * @return $this |
||
| 672 | */ |
||
| 673 | public function setReference(ViewReference $reference = null, $locale = null) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Get CSS hash. |
||
| 684 | * |
||
| 685 | * @return string |
||
| 686 | */ |
||
| 687 | public function getCssHash() |
||
| 691 | |||
| 692 | /** |
||
| 693 | * Set CSS hash. |
||
| 694 | * |
||
| 695 | * @param string $cssHash |
||
| 696 | * |
||
| 697 | * @return $this |
||
| 698 | */ |
||
| 699 | public function setCssHash($cssHash) |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Change cssHash. |
||
| 708 | */ |
||
| 709 | public function changeCssHash() |
||
| 713 | |||
| 714 | /** |
||
| 715 | * @deprecated |
||
| 716 | * Get widgetMap |
||
| 717 | * |
||
| 718 | * @return widgetMap |
||
| 719 | */ |
||
| 720 | public function getWidgetMap() |
||
| 724 | |||
| 725 | /** |
||
| 726 | * @deprecated |
||
| 727 | * Get widgets |
||
| 728 | * |
||
| 729 | * @return string |
||
| 730 | */ |
||
| 731 | public function getWidgets() |
||
| 735 | |||
| 736 | /** |
||
| 737 | * @param View $view |
||
| 738 | * |
||
| 739 | * @return bool |
||
| 740 | */ |
||
| 741 | public function isTemplateOf(View $view) |
||
| 752 | |||
| 753 | /** |
||
| 754 | * Get cssUpToDate. |
||
| 755 | * |
||
| 756 | * @return bool |
||
| 757 | */ |
||
| 758 | public function isCssUpToDate() |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Set CssUpToDate. |
||
| 765 | * |
||
| 766 | * @param bool $cssUpToDate |
||
| 767 | * |
||
| 768 | * @return $this |
||
| 769 | */ |
||
| 770 | public function setCssUpToDate($cssUpToDate) |
||
| 776 | |||
| 777 | /** |
||
| 778 | * {@inheritdoc} |
||
| 779 | */ |
||
| 780 | public static function getTranslationEntityClass() |
||
| 784 | |||
| 785 | public function getName() |
||
| 789 | |||
| 790 | public function setName($name, $locale = null) |
||
| 795 | |||
| 796 | public function getSlug() |
||
| 800 | |||
| 801 | public function setSlug($slug, $locale = null) |
||
| 806 | |||
| 807 | /** |
||
| 808 | * @return array |
||
| 809 | */ |
||
| 810 | public function getRoles() |
||
| 814 | |||
| 815 | /** |
||
| 816 | * @param array $roles |
||
| 817 | */ |
||
| 818 | public function setRoles($roles) |
||
| 822 | } |
||
| 823 |