Complex classes like Change 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 Change, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class Change |
||
15 | { |
||
16 | /** |
||
17 | * The type of change to apply to the Page. Can be 'custom_code', 'custom_css', |
||
18 | * 'attribute', 'mobile_live_variable', 'mobile_code_block', 'mobile_visual_change', |
||
19 | * 'widget', 'insert_html', 'insert_image' or 'redirect'. |
||
20 | * @var string |
||
21 | */ |
||
22 | private $type; |
||
23 | |||
24 | /** |
||
25 | * Whether or not to allow additional redirects after redirecting to |
||
26 | * destination. Required for changes of type redirect. |
||
27 | * @var boolean |
||
28 | */ |
||
29 | private $allowAdditionalRedirect; |
||
30 | |||
31 | /** |
||
32 | * Indicates whether or not to execute the change asyncronously. |
||
33 | * @var boolean |
||
34 | */ |
||
35 | private $async; |
||
36 | |||
37 | /** |
||
38 | * CSS selector to determine where changes are applied. Required for changes |
||
39 | * of type custom_css, insert_html and insert_image. |
||
40 | * @var string |
||
41 | */ |
||
42 | private $cssSelector; |
||
|
|||
43 | |||
44 | /** |
||
45 | * A list of dependent change IDs that must happen before this change |
||
46 | * @var array[string] |
||
47 | */ |
||
48 | private $dependencies; |
||
49 | |||
50 | /** |
||
51 | * URL to redirect to. Required for changes of type redirect. |
||
52 | * @var string |
||
53 | */ |
||
54 | private $destination; |
||
55 | |||
56 | /** |
||
57 | * ID of the extension to insert. Required for changes of type extension. |
||
58 | * @var string |
||
59 | */ |
||
60 | private $extensionId; |
||
61 | |||
62 | /** |
||
63 | * Whether or not to preserve parameters from original request when |
||
64 | * redirecting to new destination URL. Required for changes of type redirect. |
||
65 | * @var boolean |
||
66 | */ |
||
67 | private $preserveParameters; |
||
68 | |||
69 | /** |
||
70 | * The Page ID to apply changes to |
||
71 | * @var string |
||
72 | */ |
||
73 | private $src; |
||
74 | |||
75 | /** |
||
76 | * The value for the change |
||
77 | * @var string |
||
78 | */ |
||
79 | private $value; |
||
80 | |||
81 | /** |
||
82 | * The ID of the change |
||
83 | * @var integer |
||
84 | */ |
||
85 | private $id; |
||
86 | |||
87 | /** |
||
88 | * CSS selector to determine where changes are applied. Required for changes |
||
89 | * of type 'attribute', 'insert_html', and 'insert_image' |
||
90 | * @var string |
||
91 | */ |
||
92 | private $selector; |
||
93 | |||
94 | /** |
||
95 | * New value(s) for the element(s) matched by 'selector'. This field is only |
||
96 | * applicable to changes of type 'attribute'. |
||
97 | * @var ChangeAttribute |
||
98 | */ |
||
99 | private $attributes; |
||
100 | |||
101 | /** |
||
102 | * A directive to place the DOM element(s) matched by 'selector' to the position |
||
103 | * of the element matched by 'insertSelector', with the relation specified by |
||
104 | * 'operator'. The supplied example moves element matched by 'selector' above the element of class .greyBox |
||
105 | * @var array |
||
106 | */ |
||
107 | private $rearrange; |
||
108 | |||
109 | /** |
||
110 | * Configuration properties for the extension |
||
111 | * @var array |
||
112 | */ |
||
113 | private $config; |
||
114 | |||
115 | /** |
||
116 | * CSS to apply to element(s) matched by 'selector'. |
||
117 | * @var CssAttribute |
||
118 | */ |
||
119 | private $css; |
||
120 | |||
121 | /** |
||
122 | * Name of the change |
||
123 | * @var string |
||
124 | */ |
||
125 | private $name; |
||
126 | |||
127 | /** |
||
128 | * Where to instert HTML or image for types 'insert_html' and 'insert_image' |
||
129 | * with respect to the element(s) matched by 'selector' |
||
130 | * @var string |
||
131 | */ |
||
132 | private $operator; |
||
133 | |||
134 | /** |
||
135 | * Constructor. |
||
136 | */ |
||
137 | 14 | public function __construct($options = array()) |
|
168 | |||
169 | /** |
||
170 | * Returns this object as array. |
||
171 | */ |
||
172 | 6 | public function toArray() |
|
203 | |||
204 | 7 | public function getType() |
|
208 | |||
209 | 14 | public function setType($type) |
|
213 | |||
214 | 6 | public function getAllowAdditionalRedirect() |
|
218 | |||
219 | 14 | public function setAllowAdditionalRedirect($allowAdditionalRedirect) |
|
223 | |||
224 | 6 | public function getAsync() |
|
228 | |||
229 | 14 | public function setAsync($async) |
|
233 | |||
234 | 6 | public function getDependencies() |
|
238 | |||
239 | 14 | public function setDependencies($dependencies) |
|
243 | |||
244 | 6 | public function getDestination() |
|
248 | |||
249 | 14 | public function setDestination($destination) |
|
253 | |||
254 | 6 | public function getExtensionId() |
|
258 | |||
259 | 12 | public function setExtensionId($extensionId) |
|
263 | |||
264 | 6 | public function getPreserveParameters() |
|
268 | |||
269 | 14 | public function setPreserveParameters($preserveParameters) |
|
273 | |||
274 | 7 | public function getSrc() |
|
278 | |||
279 | 14 | public function setSrc($src) |
|
283 | |||
284 | 7 | public function getValue() |
|
288 | |||
289 | 14 | public function setValue($value) |
|
293 | |||
294 | 6 | public function getId() |
|
298 | |||
299 | 10 | public function setId($id) |
|
303 | |||
304 | 6 | public function getSelector() |
|
308 | |||
309 | 14 | public function setSelector($selector) |
|
313 | |||
314 | 7 | public function getAttributes() |
|
318 | |||
319 | 3 | public function setAttributes($attributes) |
|
323 | |||
324 | 7 | public function getRearrange() |
|
328 | |||
329 | 1 | public function setRearrange($rearrange) |
|
333 | |||
334 | 6 | public function getConfig() |
|
338 | |||
339 | public function setConfig($config) |
||
343 | |||
344 | 6 | public function getCss() |
|
348 | |||
349 | public function setCss($css) |
||
353 | |||
354 | 6 | public function getName() |
|
358 | |||
359 | public function setName($name) |
||
363 | |||
364 | 6 | public function getOperator() |
|
368 | |||
369 | public function setOperator($operator) |
||
373 | } |
||
374 | |||
379 |
This check marks private properties in classes that are never used. Those properties can be removed.