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 |
||
28 | abstract class View |
||
29 | { |
||
30 | use \Gedmo\Timestampable\Traits\TimestampableEntity; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | * |
||
35 | * @ORM\Column(name="id", type="integer") |
||
36 | * @ORM\Id |
||
37 | * @ORM\GeneratedValue(strategy="AUTO") |
||
38 | */ |
||
39 | protected $id; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | * |
||
44 | * @Assert\NotBlank() |
||
45 | * @ORM\Column(name="name", type="string", length=255) |
||
46 | * @Serializer\Groups({"search"}) |
||
47 | * @Gedmo\Translatable |
||
48 | */ |
||
49 | protected $name; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | * |
||
54 | * @ORM\Column(name="bodyId", type="string", length=255, nullable=true) |
||
55 | */ |
||
56 | protected $bodyId; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | * |
||
61 | * @ORM\Column(name="bodyClass", type="string", length=255, nullable=true) |
||
62 | */ |
||
63 | protected $bodyClass; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | * |
||
68 | * @Gedmo\Slug(handlers={ |
||
69 | * @Gedmo\SlugHandler(class="Victoire\Bundle\BusinessEntityBundle\Handler\TwigSlugHandler" |
||
70 | * )},fields={"name"}, updatable=false, unique=false) |
||
71 | * @Gedmo\Translatable |
||
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 | * @var ViewReference[] |
||
141 | * The reference is related to viewsReferences.xml file which list all app views. |
||
142 | * This is used to speed up the routing system and identify virtual pages (BusinessPage). |
||
143 | */ |
||
144 | protected $references; |
||
145 | |||
146 | /** |
||
147 | * @var string |
||
148 | * |
||
149 | * @ORM\ManyToOne(targetEntity="\Victoire\Bundle\TemplateBundle\Entity\Template", inversedBy="inheritors", cascade={"persist"}) |
||
150 | * @ORM\JoinColumn(name="template_id", referencedColumnName="id", onDelete="CASCADE") |
||
151 | */ |
||
152 | protected $template; |
||
153 | |||
154 | /** |
||
155 | * @var string |
||
156 | * |
||
157 | * @ORM\Column(name="cssHash", type="string", length=40 ,nullable=true) |
||
158 | */ |
||
159 | protected $cssHash; |
||
160 | |||
161 | /** |
||
162 | * @deprecated |
||
163 | * @ORM\Column(name="widget_map", type="array") |
||
164 | */ |
||
165 | protected $widgetMap = []; |
||
166 | |||
167 | /** |
||
168 | * @var string |
||
169 | * |
||
170 | * @ORM\OneToMany(targetEntity="\Victoire\Bundle\WidgetBundle\Entity\Widget", mappedBy="view", cascade={"persist", "remove"}) |
||
171 | * @ORM\OrderBy({"id" = "ASC"}) |
||
172 | */ |
||
173 | protected $widgets; |
||
174 | /** |
||
175 | * @var bool |
||
176 | * |
||
177 | * @ORM\Column(name="cssUpToDate", type="boolean") |
||
178 | */ |
||
179 | protected $cssUpToDate = false; |
||
180 | |||
181 | /** |
||
182 | * @Gedmo\Locale |
||
183 | * Used locale to override Translation listener`s locale |
||
184 | * this is not a mapped field of entity metadata, just a simple property |
||
185 | * and it is not necessary because globally locale can be set in listener |
||
186 | */ |
||
187 | protected $locale; |
||
188 | |||
189 | /** |
||
190 | * Construct. |
||
191 | **/ |
||
192 | public function __construct() |
||
199 | |||
200 | /** |
||
201 | * to string. |
||
202 | * |
||
203 | * @return string |
||
204 | **/ |
||
205 | public function __toString() |
||
209 | |||
210 | /** |
||
211 | * Get id. |
||
212 | * |
||
213 | * @return int |
||
214 | */ |
||
215 | public function getId() |
||
219 | |||
220 | /** |
||
221 | * Set id. |
||
222 | * |
||
223 | * @param id $id |
||
224 | */ |
||
225 | public function setId($id) |
||
229 | |||
230 | /** |
||
231 | * Get name. |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function getName() |
||
239 | |||
240 | /** |
||
241 | * Set name. |
||
242 | * |
||
243 | * @param string $name |
||
244 | * |
||
245 | * @return View |
||
246 | */ |
||
247 | public function setName($name) |
||
253 | |||
254 | /** |
||
255 | * Set slug. |
||
256 | * |
||
257 | * @param string $slug |
||
258 | * |
||
259 | * @return View |
||
260 | */ |
||
261 | public function setSlug($slug) |
||
267 | |||
268 | /** |
||
269 | * Get slug. |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | public function getSlug() |
||
277 | |||
278 | /** |
||
279 | * Set template. |
||
280 | * |
||
281 | * @param View $template |
||
282 | * |
||
283 | * @return View |
||
284 | */ |
||
285 | public function setTemplate($template) |
||
291 | |||
292 | /** |
||
293 | * Get template. |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public function getTemplate() |
||
301 | |||
302 | /** |
||
303 | * Set parent. |
||
304 | * |
||
305 | * @param View $parent |
||
306 | */ |
||
307 | public function setParent(View $parent = null) |
||
311 | |||
312 | /** |
||
313 | * Get parent. |
||
314 | * |
||
315 | * @return View parent |
||
316 | */ |
||
317 | public function getParent() |
||
321 | |||
322 | /** |
||
323 | * Set children. |
||
324 | * |
||
325 | * @param View[] $children |
||
326 | * |
||
327 | * @return View |
||
328 | */ |
||
329 | public function setChildren($children) |
||
340 | |||
341 | /** |
||
342 | * Get children. |
||
343 | * |
||
344 | * @return View[] |
||
345 | */ |
||
346 | public function getChildren() |
||
350 | |||
351 | /** |
||
352 | * Has children. |
||
353 | * |
||
354 | * @return int |
||
355 | */ |
||
356 | public function hasChildren() |
||
360 | |||
361 | /** |
||
362 | * Get WebView children. |
||
363 | * |
||
364 | * @return string |
||
365 | */ |
||
366 | public function getWebViewChildren() |
||
377 | |||
378 | /** |
||
379 | * Add child. |
||
380 | * |
||
381 | * @param View $child |
||
382 | */ |
||
383 | public function addChild(View $child) |
||
387 | |||
388 | /** |
||
389 | * Remove child. |
||
390 | * |
||
391 | * @param View $child |
||
392 | */ |
||
393 | public function removeChild(View $child) |
||
397 | |||
398 | /** |
||
399 | * Get the left value. |
||
400 | * |
||
401 | * @return int |
||
402 | */ |
||
403 | public function getLft() |
||
407 | |||
408 | /** |
||
409 | * Set the left value. |
||
410 | * |
||
411 | * @param int $lft |
||
412 | */ |
||
413 | public function setLft($lft) |
||
417 | |||
418 | /** |
||
419 | * Get the right value. |
||
420 | * |
||
421 | * @return int |
||
422 | */ |
||
423 | public function getRgt() |
||
427 | |||
428 | /** |
||
429 | * Set the right value. |
||
430 | * |
||
431 | * @param int $rgt |
||
432 | */ |
||
433 | public function setRgt($rgt) |
||
437 | |||
438 | /** |
||
439 | * Get the level value. |
||
440 | * |
||
441 | * @return int |
||
442 | */ |
||
443 | public function getLvl() |
||
447 | |||
448 | /** |
||
449 | * Set the level value. |
||
450 | * |
||
451 | * @param int $lvl |
||
452 | */ |
||
453 | public function setLvl($lvl) |
||
457 | |||
458 | /** |
||
459 | * Get the root value. |
||
460 | * |
||
461 | * @return int |
||
462 | */ |
||
463 | public function getRoot() |
||
467 | |||
468 | /** |
||
469 | * Set the root value. |
||
470 | * |
||
471 | * @param int $root |
||
472 | */ |
||
473 | public function setRoot($root) |
||
477 | |||
478 | /** |
||
479 | * Set undeletable. |
||
480 | * |
||
481 | * @param bool $undeletable |
||
482 | * |
||
483 | * @return View The current instance |
||
484 | */ |
||
485 | public function setUndeletable($undeletable) |
||
491 | |||
492 | /** |
||
493 | * Is the widget is undeletable. |
||
494 | * |
||
495 | * @return string |
||
496 | */ |
||
497 | public function isUndeletable() |
||
501 | |||
502 | /** |
||
503 | * Get author. |
||
504 | * |
||
505 | * @return string |
||
506 | */ |
||
507 | public function getAuthor() |
||
511 | |||
512 | /** |
||
513 | * Set author. |
||
514 | * |
||
515 | * @param string $author |
||
516 | * |
||
517 | * @return $this |
||
518 | */ |
||
519 | public function setAuthor($author) |
||
525 | |||
526 | /** |
||
527 | * Get bodyId. |
||
528 | * |
||
529 | * @return string |
||
530 | */ |
||
531 | public function getBodyId() |
||
535 | |||
536 | /** |
||
537 | * Set bodyId. |
||
538 | * |
||
539 | * @param string $bodyId |
||
540 | * |
||
541 | * @return $this |
||
542 | */ |
||
543 | public function setBodyId($bodyId) |
||
549 | |||
550 | /** |
||
551 | * Get bodyClass. |
||
552 | * |
||
553 | * @return string |
||
554 | */ |
||
555 | public function getBodyClass() |
||
559 | |||
560 | /** |
||
561 | * Set bodyClass. |
||
562 | * |
||
563 | * @param string $bodyClass |
||
564 | * |
||
565 | * @return $this |
||
566 | */ |
||
567 | public function setBodyClass($bodyClass) |
||
573 | |||
574 | /** |
||
575 | * Set widgets. |
||
576 | * |
||
577 | * @param [WidgetMap] $widgetMaps |
||
578 | * |
||
579 | * @return View |
||
580 | */ |
||
581 | public function setWidgetMaps($widgetMaps) |
||
587 | |||
588 | /** |
||
589 | * Get widgets. |
||
590 | * |
||
591 | * @return Collection[WidgetMap] |
||
592 | */ |
||
593 | public function getWidgetMaps() |
||
597 | |||
598 | /** |
||
599 | * Add widget. |
||
600 | * |
||
601 | * @param Widget $widgetMap |
||
602 | */ |
||
603 | public function addWidgetMap(WidgetMap $widgetMap) |
||
610 | |||
611 | /** |
||
612 | * Remove a widgetMap. |
||
613 | * |
||
614 | * @param WidgetMap $widgetMap |
||
615 | */ |
||
616 | public function removeWidgetMap(WidgetMap $widgetMap) |
||
620 | |||
621 | /** |
||
622 | * Get widgets ids as array. |
||
623 | * |
||
624 | * @return array |
||
625 | */ |
||
626 | public function getWidgetsIds() |
||
637 | |||
638 | /** |
||
639 | * Get builtWidgetMap. |
||
640 | * |
||
641 | * @return array |
||
642 | */ |
||
643 | public function getBuiltWidgetMap() |
||
647 | |||
648 | /** |
||
649 | * Set builtWidgetMap. |
||
650 | * |
||
651 | * @param string $builtWidgetMap |
||
652 | * |
||
653 | * @return $this |
||
654 | */ |
||
655 | public function setBuiltWidgetMap($builtWidgetMap) |
||
661 | |||
662 | /** |
||
663 | * Get discriminator type. |
||
664 | * |
||
665 | * @return int |
||
666 | */ |
||
667 | public function getType() |
||
673 | |||
674 | /** |
||
675 | * Set position. |
||
676 | * |
||
677 | * @param int $position |
||
678 | */ |
||
679 | public function setPosition($position) |
||
683 | |||
684 | /** |
||
685 | * Get position. |
||
686 | * |
||
687 | * @return int |
||
688 | */ |
||
689 | public function getPosition() |
||
693 | |||
694 | /** |
||
695 | * Get reference according to the current locale. |
||
696 | * |
||
697 | * @param string $locale |
||
698 | * |
||
699 | * @return null|ViewReference |
||
700 | */ |
||
701 | public function getReference($locale = null) |
||
708 | |||
709 | /** |
||
710 | * Get references. |
||
711 | * |
||
712 | * @return ViewReference[] |
||
713 | */ |
||
714 | public function getReferences() |
||
718 | |||
719 | /** |
||
720 | * Set references. |
||
721 | * |
||
722 | * @param ViewReference[] $references |
||
723 | * |
||
724 | * @return $this |
||
725 | */ |
||
726 | public function setReferences($references) |
||
732 | |||
733 | /** |
||
734 | * Set reference. |
||
735 | * |
||
736 | * @param ViewReference $reference |
||
737 | * @param string $locale |
||
738 | * |
||
739 | * @return $this |
||
740 | */ |
||
741 | public function setReference(ViewReference $reference, $locale = null) |
||
748 | |||
749 | /** |
||
750 | * Get CSS hash. |
||
751 | * |
||
752 | * @return string |
||
753 | */ |
||
754 | public function getCssHash() |
||
758 | |||
759 | /** |
||
760 | * Set CSS hash. |
||
761 | * |
||
762 | * @param string $cssHash |
||
763 | * |
||
764 | * @return $this |
||
765 | */ |
||
766 | public function setCssHash($cssHash) |
||
772 | |||
773 | /** |
||
774 | * Change cssHash. |
||
775 | */ |
||
776 | public function changeCssHash() |
||
780 | |||
781 | /** |
||
782 | * @deprecated |
||
783 | * Get widgetMap. |
||
784 | * |
||
785 | * @return widgetMap |
||
786 | */ |
||
787 | public function getWidgetMap() |
||
791 | |||
792 | /** |
||
793 | * @deprecated |
||
794 | * Get widgets. |
||
795 | * |
||
796 | * @return string |
||
797 | */ |
||
798 | public function getWidgets() |
||
802 | |||
803 | public function isTemplateOf(View $view) |
||
814 | |||
815 | /** |
||
816 | * Get cssUpToDate. |
||
817 | * |
||
818 | * @return bool |
||
819 | */ |
||
820 | public function isCssUpToDate() |
||
824 | |||
825 | /** |
||
826 | * Set CssUpToDate. |
||
827 | * |
||
828 | * @param bool $cssUpToDate |
||
829 | * |
||
830 | * @return $this |
||
831 | */ |
||
832 | public function setCssUpToDate($cssUpToDate) |
||
838 | |||
839 | public function setTranslatableLocale($locale) |
||
843 | |||
844 | /** |
||
845 | * @return string |
||
846 | */ |
||
847 | public function getLocale() |
||
851 | } |
||
852 |
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..