Complex classes like Event 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 Event, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Event |
||
17 | { |
||
18 | /** |
||
19 | * A machine readable name for this Event |
||
20 | * @var string |
||
21 | */ |
||
22 | private $apiName; |
||
23 | |||
24 | /** |
||
25 | * Whether or not this Event has been archived |
||
26 | * @var boolean |
||
27 | */ |
||
28 | private $archived; |
||
29 | |||
30 | /** |
||
31 | * A category for this Event. Can be 'add_to_cart', 'save', 'search', 'share', |
||
32 | * 'purchase', 'convert', 'sign_up', 'subscribe' or 'other'. |
||
33 | * @var type |
||
34 | */ |
||
35 | private $category; |
||
36 | |||
37 | /** |
||
38 | * Creation date for this Event |
||
39 | * @var string |
||
40 | */ |
||
41 | private $created; |
||
42 | |||
43 | /** |
||
44 | * Last modified date. |
||
45 | * @var string |
||
46 | */ |
||
47 | private $lastModified; |
||
48 | |||
49 | /** |
||
50 | * A description for this Event |
||
51 | * @var string |
||
52 | */ |
||
53 | private $description; |
||
54 | |||
55 | /** |
||
56 | * A filter object for this Event |
||
57 | * @var EventFilter |
||
58 | */ |
||
59 | private $eventFilter; |
||
60 | |||
61 | /** |
||
62 | * The type of this Event. Can be custom, click, pageview, classic_custom, |
||
63 | * classic_click, classic_pageview, classic_engagement, classic_revenue, |
||
64 | * classic_mobile_tap, classic_mobile_view, classic_mobile_session, |
||
65 | * classic_mobile_session_length or classic_mobile_num_session |
||
66 | * @var string |
||
67 | */ |
||
68 | private $eventType; |
||
69 | |||
70 | /** |
||
71 | * Unique string identifier for this event within the project. |
||
72 | * @var string |
||
73 | */ |
||
74 | private $key; |
||
75 | |||
76 | /** |
||
77 | * A human readable name for this Event |
||
78 | * @var string |
||
79 | */ |
||
80 | private $name; |
||
81 | |||
82 | /** |
||
83 | * The Page ID associated with this Event |
||
84 | * @var integer |
||
85 | */ |
||
86 | private $pageId; |
||
87 | |||
88 | /** |
||
89 | * The parent Project ID of this Event |
||
90 | * @var integer |
||
91 | */ |
||
92 | private $projectId; |
||
93 | |||
94 | /** |
||
95 | * The unique identifier of the Event |
||
96 | * @var integer |
||
97 | */ |
||
98 | private $id; |
||
99 | |||
100 | /** |
||
101 | * Whether or not this Event is a classic Event |
||
102 | * @var boolean |
||
103 | */ |
||
104 | private $isClassic; |
||
105 | |||
106 | /** |
||
107 | * Whether this Event may be edited |
||
108 | * @var boolean |
||
109 | */ |
||
110 | private $isEditable; |
||
111 | |||
112 | /** |
||
113 | * |
||
114 | * @var InPageEventConfig |
||
115 | */ |
||
116 | private $config; |
||
117 | |||
118 | /** |
||
119 | * Constructor. |
||
120 | */ |
||
121 | 9 | public function __construct($options = array()) |
|
146 | |||
147 | /** |
||
148 | * Returns this object as array. |
||
149 | */ |
||
150 | 5 | public function toArray() |
|
180 | |||
181 | 5 | public function getApiName() |
|
185 | |||
186 | public function setApiName($apiName) |
||
190 | |||
191 | 7 | public function getArchived() |
|
195 | |||
196 | 9 | public function setArchived($archived) |
|
200 | |||
201 | 7 | public function getCategory() |
|
205 | |||
206 | 9 | public function setCategory($category) |
|
210 | |||
211 | 5 | public function getCreated() |
|
215 | |||
216 | 9 | public function setCreated($created) |
|
220 | |||
221 | 5 | public function getLastModified() |
|
225 | |||
226 | public function setLastModified($lastModified) |
||
230 | |||
231 | 5 | public function getDescription() |
|
235 | |||
236 | 9 | public function setDescription($description) |
|
240 | |||
241 | 7 | public function getEventFilter() |
|
245 | |||
246 | 7 | public function setEventFilter($eventFilter) |
|
250 | |||
251 | 5 | public function getEventType() |
|
255 | |||
256 | 9 | public function setEventType($eventType) |
|
260 | |||
261 | 5 | public function getKey() |
|
265 | |||
266 | 9 | public function setKey($key) |
|
270 | |||
271 | 9 | public function getName() |
|
275 | |||
276 | 9 | public function setName($name) |
|
280 | |||
281 | 5 | public function getPageId() |
|
285 | |||
286 | 9 | public function setPageId($pageId) |
|
290 | |||
291 | 5 | public function getProjectId() |
|
295 | |||
296 | 9 | public function setProjectId($projectId) |
|
300 | |||
301 | 5 | public function getId() |
|
305 | |||
306 | 9 | public function setId($id) |
|
310 | |||
311 | 5 | public function getIsClassic() |
|
315 | |||
316 | 9 | public function setIsClassic($isClassic) |
|
320 | |||
321 | 7 | public function getIsEditable() |
|
325 | |||
326 | 9 | public function setIsEditable($isEditable) |
|
330 | |||
331 | 5 | public function getConfig() |
|
335 | |||
336 | public function setConfig($config) |
||
340 | } |
||
341 | |||
347 |