Complex classes like Page 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 Page, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class Page extends Seo |
||
15 | { |
||
16 | /** |
||
17 | * @orm\Column(length=64) |
||
18 | */ |
||
19 | private $title; |
||
20 | |||
21 | /** |
||
22 | * @gedmo\Slug(fields={"title"}) |
||
23 | * @orm\Column(length=64, unique=true) |
||
24 | */ |
||
25 | private $slug; |
||
26 | |||
27 | /** |
||
28 | * @gedmo\TreeLeft |
||
29 | * @orm\Column(type="integer") |
||
30 | */ |
||
31 | private $lft; |
||
32 | |||
33 | /** |
||
34 | * @gedmo\TreeRight |
||
35 | * @orm\Column(type="integer") |
||
36 | */ |
||
37 | private $rgt; |
||
38 | |||
39 | /** |
||
40 | * @gedmo\TreeParent |
||
41 | * @orm\ManyToOne(targetEntity="Page", inversedBy="children") |
||
42 | * @orm\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") |
||
43 | */ |
||
44 | private $parent; |
||
45 | |||
46 | /** |
||
47 | * @gedmo\TreeRoot |
||
48 | * @orm\Column(type="integer", nullable=true) |
||
49 | */ |
||
50 | private $root; |
||
51 | |||
52 | /** |
||
53 | * @gedmo\TreeLevel |
||
54 | * @orm\Column(name="lvl", type="integer") |
||
55 | */ |
||
56 | private $level; |
||
57 | |||
58 | /** |
||
59 | * @orm\OneToMany(targetEntity="Page", mappedBy="parent") |
||
60 | */ |
||
61 | private $children; |
||
62 | |||
63 | /** |
||
64 | * @gedmo\Timestampable(on="create") |
||
65 | * @orm\Column(type="datetime") |
||
66 | */ |
||
67 | private $created; |
||
68 | |||
69 | /** |
||
70 | * @gedmo\Timestampable(on="update") |
||
71 | * @orm\Column(type="datetime") |
||
72 | */ |
||
73 | private $updated; |
||
74 | |||
75 | /** |
||
76 | * @orm\ManyToOne(targetEntity="Language") |
||
77 | * @orm\JoinColumn(name="language_id", referencedColumnName="id", onDelete="CASCADE") |
||
78 | */ |
||
79 | private $language; |
||
80 | |||
81 | /** |
||
82 | * @orm\ManyToOne(targetEntity="Module") |
||
83 | * @orm\JoinColumn(name="module_id", referencedColumnName="id", onDelete="SET NULL", nullable=true) |
||
84 | */ |
||
85 | private $module; |
||
86 | |||
87 | /** |
||
88 | * @orm\Column(nullable=true) |
||
89 | */ |
||
90 | private $moduleName; |
||
91 | |||
92 | /** |
||
93 | * @orm\Column |
||
94 | */ |
||
95 | private $presenter; |
||
96 | |||
97 | /** |
||
98 | * @orm\Column |
||
99 | */ |
||
100 | private $path; |
||
101 | |||
102 | /** |
||
103 | * @orm\Column(type="boolean") |
||
104 | */ |
||
105 | public $visible; |
||
106 | |||
107 | /** |
||
108 | * @orm\Column(type="boolean", name="`default`") |
||
109 | */ |
||
110 | private $default; |
||
111 | |||
112 | /** |
||
113 | * @orm\Column(type="boolean") |
||
114 | */ |
||
115 | public $secured = false; |
||
116 | |||
117 | /** |
||
118 | * @orm\Column |
||
119 | */ |
||
120 | private $class; |
||
121 | |||
122 | /** |
||
123 | * @orm\OneToMany(targetEntity="Box", mappedBy="pageTo") |
||
124 | */ |
||
125 | private $boxes; |
||
126 | |||
127 | /** |
||
128 | * @orm\Column(nullable=true) |
||
129 | */ |
||
130 | private $redirect; |
||
131 | |||
132 | /** |
||
133 | * @orm\Column(type="text", nullable=true) |
||
134 | */ |
||
135 | private $layout; |
||
136 | |||
137 | 2 | public function __construct() |
|
141 | |||
142 | public function getSlug() |
||
146 | |||
147 | public function getId() |
||
151 | |||
152 | 2 | public function setTitle($title) |
|
156 | |||
157 | public function getTitle() |
||
161 | |||
162 | public function setParent($parent) |
||
166 | |||
167 | public function getParent() |
||
171 | |||
172 | public function getRoot() |
||
176 | |||
177 | public function getLevel() |
||
181 | |||
182 | public function getChildren() |
||
186 | |||
187 | public function getLeft() |
||
191 | |||
192 | public function getRight() |
||
196 | |||
197 | public function getCreated() |
||
201 | |||
202 | public function getUpdated() |
||
206 | |||
207 | public function getLanguage() |
||
211 | |||
212 | public function setLanguage($language) |
||
216 | |||
217 | public function getVisible() |
||
221 | |||
222 | 2 | public function setVisible($visible) |
|
226 | |||
227 | public function getDefault() |
||
231 | |||
232 | 2 | public function setDefault($default) |
|
236 | |||
237 | public function getSecured() |
||
241 | |||
242 | public function setSecured($secured) |
||
246 | |||
247 | public function getModule() |
||
251 | |||
252 | public function setModule($module) |
||
256 | |||
257 | public function getPresenter() |
||
261 | |||
262 | 2 | public function setPresenter($presenter) |
|
266 | |||
267 | public function getModuleName() |
||
271 | |||
272 | public function setModuleName($moduleName) |
||
276 | |||
277 | public function getPath() |
||
281 | |||
282 | /** |
||
283 | * @param string $path |
||
284 | */ |
||
285 | 2 | public function setPath($path) |
|
289 | |||
290 | public function getClass() |
||
294 | |||
295 | 2 | public function setClass($class) |
|
299 | |||
300 | public function __toString() |
||
304 | |||
305 | public function getBoxes() |
||
309 | |||
310 | /** |
||
311 | * @param Box[] $boxes |
||
312 | */ |
||
313 | public function setBoxes($boxes) |
||
317 | |||
318 | public function getBox($name) |
||
328 | |||
329 | /** |
||
330 | * @param string $slug |
||
331 | */ |
||
332 | public function setSlug($slug) |
||
336 | |||
337 | public function getRedirect() |
||
341 | |||
342 | /** |
||
343 | * @param boolean $redirect |
||
344 | */ |
||
345 | public function setRedirect($redirect) |
||
349 | |||
350 | /** |
||
351 | * Gets the value of layout. |
||
352 | * |
||
353 | * @return mixed |
||
354 | */ |
||
355 | public function getLayout() |
||
359 | |||
360 | /** |
||
361 | * Sets the value of layout. |
||
362 | * |
||
363 | * @param mixed $layout the layout |
||
364 | * |
||
365 | * @return self |
||
366 | */ |
||
367 | public function setLayout($layout) |
||
373 | } |
||
374 |