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 | |||
| 34 | /** |
||
| 35 | * @var int |
||
| 36 | * |
||
| 37 | * @ORM\Column(name="id", type="integer") |
||
| 38 | * @ORM\Id |
||
| 39 | * @ORM\GeneratedValue(strategy="AUTO") |
||
| 40 | */ |
||
| 41 | protected $id; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | * |
||
| 46 | * @Assert\NotBlank() |
||
| 47 | * @ORM\Column(name="name", type="string", length=255) |
||
| 48 | * @Serializer\Groups({"search"}) |
||
| 49 | */ |
||
| 50 | protected $name; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | * |
||
| 55 | * @ORM\Column(name="bodyId", type="string", length=255, nullable=true) |
||
| 56 | */ |
||
| 57 | protected $bodyId; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | * |
||
| 62 | * @ORM\Column(name="bodyClass", type="string", length=255, nullable=true) |
||
| 63 | */ |
||
| 64 | protected $bodyClass; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | * |
||
| 69 | * @Gedmo\Slug(handlers={ |
||
| 70 | * @Gedmo\SlugHandler(class="Victoire\Bundle\BusinessEntityBundle\Handler\TwigSlugHandler" |
||
| 71 | * )},fields={"name"}, updatable=false, unique=false) |
||
| 72 | * @ORM\Column(name="slug", type="string", length=255) |
||
| 73 | */ |
||
| 74 | protected $slug; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var [WidgetMap] |
||
| 78 | * |
||
| 79 | * @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetMapBundle\Entity\WidgetMap", mappedBy="view", orphanRemoval=true, cascade={"persist", "remove"}) |
||
| 80 | */ |
||
| 81 | protected $widgetMaps = []; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @Gedmo\TreeParent |
||
| 85 | * @ORM\ManyToOne(targetEntity="View", inversedBy="children", cascade={"persist"}) |
||
| 86 | * @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
||
| 87 | */ |
||
| 88 | protected $parent; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var int |
||
| 92 | * |
||
| 93 | * @ORM\Column(name="position", type="integer", nullable=false) |
||
| 94 | */ |
||
| 95 | protected $position = 0; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @Gedmo\TreeLeft |
||
| 99 | * @ORM\Column(name="lft", type="integer") |
||
| 100 | */ |
||
| 101 | protected $lft; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @Gedmo\TreeLevel |
||
| 105 | * @ORM\Column(name="lvl", type="integer") |
||
| 106 | */ |
||
| 107 | protected $lvl; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @Gedmo\TreeRight |
||
| 111 | * @ORM\Column(name="rgt", type="integer") |
||
| 112 | */ |
||
| 113 | protected $rgt; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @Gedmo\TreeRoot |
||
| 117 | * @ORM\Column(name="root", type="integer", nullable=true) |
||
| 118 | */ |
||
| 119 | protected $root; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @ORM\OneToMany(targetEntity="View", mappedBy="parent", cascade={"remove"}) |
||
| 123 | * @ORM\OrderBy({"lft" = "ASC"}) |
||
| 124 | */ |
||
| 125 | protected $children = []; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * This relation is dynamicly added by PageSubscriber. |
||
| 129 | */ |
||
| 130 | protected $author; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var string |
||
| 134 | * |
||
| 135 | * @ORM\Column(name="undeletable", type="boolean") |
||
| 136 | */ |
||
| 137 | protected $undeletable = false; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * The reference is related to viewsReferences.xml file which list all app views. |
||
| 141 | * This is used to speed up the routing system and identify virtual pages (BusinessPage). |
||
| 142 | */ |
||
| 143 | protected $reference; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @ORM\Column(name="locale", type="string") |
||
| 147 | * @Serializer\Groups({"search"}) |
||
| 148 | */ |
||
| 149 | protected $locale; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @var string |
||
| 153 | * |
||
| 154 | * @ORM\OneToOne(targetEntity="\Victoire\Bundle\I18nBundle\Entity\I18n", cascade={"persist", "remove"}) |
||
| 155 | * @ORM\JoinColumn(name="i18n_id", referencedColumnName="id", onDelete="SET NULL") |
||
| 156 | */ |
||
| 157 | protected $i18n; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var string |
||
| 161 | * |
||
| 162 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\TemplateBundle\Entity\Template", inversedBy="inheritors", cascade={"persist"}) |
||
| 163 | * @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE") |
||
| 164 | */ |
||
| 165 | protected $template; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @var string |
||
| 169 | * |
||
| 170 | * @ORM\Column(name="cssHash", type="string", length=40 ,nullable=true) |
||
| 171 | */ |
||
| 172 | protected $cssHash; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @deprecated |
||
| 176 | * @ORM\Column(name="widget_map", type="array") |
||
| 177 | */ |
||
| 178 | protected $widgetMap = []; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @var string |
||
| 182 | * |
||
| 183 | * @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetBundle\Entity\Widget", mappedBy="view", cascade={"persist", "remove"}) |
||
| 184 | * @ORM\OrderBy({"id" = "ASC"}) |
||
| 185 | */ |
||
| 186 | protected $widgets; |
||
| 187 | /** |
||
| 188 | * @var bool |
||
| 189 | * |
||
| 190 | * @ORM\Column(name="cssUpToDate", type="boolean") |
||
| 191 | */ |
||
| 192 | protected $cssUpToDate = false; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Construct. |
||
| 196 | **/ |
||
| 197 | public function __construct() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * to string. |
||
| 206 | * |
||
| 207 | * @return string |
||
| 208 | **/ |
||
| 209 | public function __toString() |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Get id. |
||
| 216 | * |
||
| 217 | * @return int |
||
| 218 | */ |
||
| 219 | public function getId() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Set id. |
||
| 226 | * |
||
| 227 | * @param id $id |
||
| 228 | */ |
||
| 229 | public function setId($id) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get locale. |
||
| 236 | * |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | public function getLocale() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Set locale. |
||
| 246 | * |
||
| 247 | * @param $locale |
||
| 248 | */ |
||
| 249 | public function setLocale($locale) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get name. |
||
| 256 | * |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | public function getName() |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Set name. |
||
| 266 | * |
||
| 267 | * @param string $name |
||
| 268 | * |
||
| 269 | * @return View |
||
| 270 | */ |
||
| 271 | public function setName($name) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Set slug. |
||
| 280 | * |
||
| 281 | * @param string $slug |
||
| 282 | * |
||
| 283 | * @return View |
||
| 284 | */ |
||
| 285 | public function setSlug($slug) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get slug. |
||
| 294 | * |
||
| 295 | * @return string |
||
| 296 | */ |
||
| 297 | public function getSlug() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Set template. |
||
| 304 | * |
||
| 305 | * @param View $template |
||
| 306 | * |
||
| 307 | * @return View |
||
| 308 | */ |
||
| 309 | public function setTemplate($template) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Get template. |
||
| 318 | * |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | public function getTemplate() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Set parent. |
||
| 328 | * |
||
| 329 | * @param View $parent |
||
| 330 | */ |
||
| 331 | public function setParent(View $parent = null) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Get parent. |
||
| 338 | * |
||
| 339 | * @return View parent |
||
| 340 | */ |
||
| 341 | public function getParent() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Set children. |
||
| 348 | * |
||
| 349 | * @param View[] $children |
||
| 350 | * |
||
| 351 | * @return View |
||
| 352 | */ |
||
| 353 | public function setChildren($children) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Get children. |
||
| 367 | * |
||
| 368 | * @return View[] |
||
| 369 | */ |
||
| 370 | public function getChildren() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * Has children. |
||
| 377 | * |
||
| 378 | * @return int |
||
| 379 | */ |
||
| 380 | public function hasChildren() |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Get WebView children. |
||
| 387 | * |
||
| 388 | * @return string |
||
| 389 | */ |
||
| 390 | public function getWebViewChildren() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Add child. |
||
| 404 | * |
||
| 405 | * @param View $child |
||
| 406 | */ |
||
| 407 | public function addChild(View $child) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Remove child. |
||
| 414 | * |
||
| 415 | * @param View $child |
||
| 416 | */ |
||
| 417 | public function removeChild(View $child) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Get the left value. |
||
| 424 | * |
||
| 425 | * @return int |
||
| 426 | */ |
||
| 427 | public function getLft() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Set the left value. |
||
| 434 | * |
||
| 435 | * @param int $lft |
||
| 436 | */ |
||
| 437 | public function setLft($lft) |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Get the right value. |
||
| 444 | * |
||
| 445 | * @return int |
||
| 446 | */ |
||
| 447 | public function getRgt() |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Set the right value. |
||
| 454 | * |
||
| 455 | * @param int $rgt |
||
| 456 | */ |
||
| 457 | public function setRgt($rgt) |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Get the level value. |
||
| 464 | * |
||
| 465 | * @return int |
||
| 466 | */ |
||
| 467 | public function getLvl() |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Set the level value. |
||
| 474 | * |
||
| 475 | * @param int $lvl |
||
| 476 | */ |
||
| 477 | public function setLvl($lvl) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Get the root value. |
||
| 484 | * |
||
| 485 | * @return int |
||
| 486 | */ |
||
| 487 | public function getRoot() |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Set the root value. |
||
| 494 | * |
||
| 495 | * @param int $root |
||
| 496 | */ |
||
| 497 | public function setRoot($root) |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Set undeletable. |
||
| 504 | * |
||
| 505 | * @param bool $undeletable |
||
| 506 | * |
||
| 507 | * @return View The current instance |
||
| 508 | */ |
||
| 509 | public function setUndeletable($undeletable) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Is the widget is undeletable. |
||
| 518 | * |
||
| 519 | * @return string |
||
| 520 | */ |
||
| 521 | public function isUndeletable() |
||
| 525 | |||
| 526 | /** |
||
| 527 | * Get author. |
||
| 528 | * |
||
| 529 | * @return string |
||
| 530 | */ |
||
| 531 | public function getAuthor() |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Set author. |
||
| 538 | * |
||
| 539 | * @param string $author |
||
| 540 | * |
||
| 541 | * @return $this |
||
| 542 | */ |
||
| 543 | public function setAuthor($author) |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Get bodyId. |
||
| 552 | * |
||
| 553 | * @return string |
||
| 554 | */ |
||
| 555 | public function getBodyId() |
||
| 559 | |||
| 560 | /** |
||
| 561 | * Set bodyId. |
||
| 562 | * |
||
| 563 | * @param string $bodyId |
||
| 564 | * |
||
| 565 | * @return $this |
||
| 566 | */ |
||
| 567 | public function setBodyId($bodyId) |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Get bodyClass. |
||
| 576 | * |
||
| 577 | * @return string |
||
| 578 | */ |
||
| 579 | public function getBodyClass() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Set bodyClass. |
||
| 586 | * |
||
| 587 | * @param string $bodyClass |
||
| 588 | * |
||
| 589 | * @return $this |
||
| 590 | */ |
||
| 591 | public function setBodyClass($bodyClass) |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Initialize I18n table. |
||
| 600 | * |
||
| 601 | * @ORM\PrePersist |
||
| 602 | */ |
||
| 603 | public function initI18n() |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Get i18n. |
||
| 613 | * |
||
| 614 | * @return string |
||
| 615 | */ |
||
| 616 | public function getI18n() |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Set i18n. |
||
| 623 | * |
||
| 624 | * @param BaseI18n $i18n |
||
| 625 | * |
||
| 626 | * @return $this |
||
| 627 | */ |
||
| 628 | public function setI18n(BaseI18n $i18n) |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Set widgets. |
||
| 638 | * |
||
| 639 | * @param [WidgetMap] $widgetMaps |
||
| 640 | * |
||
| 641 | * @return View |
||
| 642 | */ |
||
| 643 | public function setWidgetMaps($widgetMaps) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Get widgets. |
||
| 652 | * |
||
| 653 | * @return Collection[WidgetMap] |
||
| 654 | */ |
||
| 655 | public function getWidgetMaps() |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Add widget. |
||
| 662 | * |
||
| 663 | * @param Widget $widgetMap |
||
| 664 | */ |
||
| 665 | public function addWidgetMap(WidgetMap $widgetMap) |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Remove a widgetMap. |
||
| 675 | * |
||
| 676 | * @param WidgetMap $widgetMap |
||
| 677 | */ |
||
| 678 | public function removeWidgetMap(WidgetMap $widgetMap) |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Get widgets ids as array. |
||
| 685 | * |
||
| 686 | * @return array |
||
| 687 | */ |
||
| 688 | public function getWidgetsIds() |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Get builtWidgetMap. |
||
| 701 | * |
||
| 702 | * @return array |
||
| 703 | */ |
||
| 704 | public function getBuiltWidgetMap() |
||
| 708 | |||
| 709 | /** |
||
| 710 | * Set builtWidgetMap. |
||
| 711 | * |
||
| 712 | * @param string $builtWidgetMap |
||
| 713 | * |
||
| 714 | * @return $this |
||
| 715 | */ |
||
| 716 | public function setBuiltWidgetMap($builtWidgetMap) |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Get discriminator type. |
||
| 725 | * |
||
| 726 | * @return int |
||
| 727 | */ |
||
| 728 | public function getType() |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Set position. |
||
| 737 | * |
||
| 738 | * @param int $position |
||
| 739 | */ |
||
| 740 | public function setPosition($position) |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Get position. |
||
| 747 | * |
||
| 748 | * @return int |
||
| 749 | */ |
||
| 750 | public function getPosition() |
||
| 754 | |||
| 755 | /** |
||
| 756 | * Get reference. |
||
| 757 | * |
||
| 758 | * @return ViewReference |
||
| 759 | */ |
||
| 760 | public function getReference() |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Set reference. |
||
| 767 | * |
||
| 768 | * @param ViewReference $reference |
||
| 769 | * |
||
| 770 | * @return $this |
||
| 771 | */ |
||
| 772 | public function setReference($reference) |
||
| 778 | |||
| 779 | /** |
||
| 780 | * Get CSS hash. |
||
| 781 | * |
||
| 782 | * @return string |
||
| 783 | */ |
||
| 784 | public function getCssHash() |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Set CSS hash. |
||
| 791 | * |
||
| 792 | * @param string $cssHash |
||
| 793 | * |
||
| 794 | * @return $this |
||
| 795 | */ |
||
| 796 | public function setCssHash($cssHash) |
||
| 802 | |||
| 803 | /** |
||
| 804 | * Change cssHash. |
||
| 805 | */ |
||
| 806 | public function changeCssHash() |
||
| 810 | |||
| 811 | /** |
||
| 812 | * @deprecated |
||
| 813 | * Get widgetMap. |
||
| 814 | * |
||
| 815 | * @return widgetMap |
||
| 816 | */ |
||
| 817 | public function getWidgetMap() |
||
| 821 | |||
| 822 | /** |
||
| 823 | * @deprecated |
||
| 824 | * Get widgets. |
||
| 825 | * |
||
| 826 | * @return string |
||
| 827 | */ |
||
| 828 | public function getWidgets() |
||
| 832 | |||
| 833 | public function isTemplateOf(View $view) |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Get cssUpToDate. |
||
| 847 | * |
||
| 848 | * @return bool |
||
| 849 | */ |
||
| 850 | public function isCssUpToDate() |
||
| 854 | |||
| 855 | /** |
||
| 856 | * Set CssUpToDate. |
||
| 857 | * |
||
| 858 | * @param bool $cssUpToDate |
||
| 859 | * |
||
| 860 | * @return $this |
||
| 861 | */ |
||
| 862 | public function setCssUpToDate($cssUpToDate) |
||
| 868 | } |
||
| 869 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..