Complex classes like AdvancedEditorEntityData 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 AdvancedEditorEntityData, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
39 | class AdvancedEditorEntityData |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * @var EE_Event |
||
44 | */ |
||
45 | protected $event; |
||
46 | |||
47 | /** |
||
48 | * @var RestApiSpoofer |
||
49 | */ |
||
50 | protected $spoofer; |
||
51 | |||
52 | /** |
||
53 | * @var EE_Admin_Config |
||
54 | */ |
||
55 | protected $admin_config; |
||
56 | |||
57 | /** |
||
58 | * @var EEM_Datetime $datetime_model |
||
59 | */ |
||
60 | protected $datetime_model; |
||
61 | |||
62 | /** |
||
63 | * @var EEM_Event $event_model |
||
64 | */ |
||
65 | protected $event_model; |
||
66 | |||
67 | /** |
||
68 | * @var EEM_Price $price_model |
||
69 | */ |
||
70 | protected $price_model; |
||
71 | |||
72 | /** |
||
73 | * @var EEM_Price_Type $price_type_model |
||
74 | */ |
||
75 | protected $price_type_model; |
||
76 | |||
77 | /** |
||
78 | * @var EEM_Ticket $ticket_model |
||
79 | */ |
||
80 | protected $ticket_model; |
||
81 | /** |
||
82 | * @var EEM_Venue $venue_model |
||
83 | */ |
||
84 | protected $venue_model; |
||
85 | |||
86 | |||
87 | /** |
||
88 | * AdvancedEditorAdminForm constructor. |
||
89 | * |
||
90 | * @param EE_Event $event |
||
91 | * @param RestApiSpoofer $spoofer |
||
92 | * @param EE_Admin_Config $admin_config |
||
93 | * @param EEM_Datetime $datetime_model |
||
94 | * @param EEM_Event $event_model |
||
95 | * @param EEM_Price $price_model |
||
96 | * @param EEM_Price_Type $price_type_model |
||
97 | * @param EEM_Ticket $ticket_model |
||
98 | * @param EEM_Venue $venue_model |
||
99 | */ |
||
100 | public function __construct( |
||
122 | |||
123 | |||
124 | /** |
||
125 | * @throws EE_Error |
||
126 | * @throws InvalidArgumentException |
||
127 | * @throws InvalidDataTypeException |
||
128 | * @throws InvalidInterfaceException |
||
129 | * @throws ModelConfigurationException |
||
130 | * @throws ReflectionException |
||
131 | * @throws RestException |
||
132 | * @throws RestPasswordIncorrectException |
||
133 | * @throws RestPasswordRequiredException |
||
134 | * @throws UnexpectedEntityException |
||
135 | * @throws DomainException |
||
136 | * @since $VID:$ |
||
137 | */ |
||
138 | public function loadScriptsStyles() |
||
165 | |||
166 | |||
167 | /** |
||
168 | * @param int $eventId |
||
169 | * @return array |
||
170 | * @throws DomainException |
||
171 | * @throws EE_Error |
||
172 | * @throws InvalidArgumentException |
||
173 | * @throws InvalidDataTypeException |
||
174 | * @throws InvalidInterfaceException |
||
175 | * @throws ModelConfigurationException |
||
176 | * @throws ReflectionException |
||
177 | * @throws RestException |
||
178 | * @throws RestPasswordIncorrectException |
||
179 | * @throws RestPasswordRequiredException |
||
180 | * @throws UnexpectedEntityException |
||
181 | * @since $VID:$ |
||
182 | */ |
||
183 | protected function getEventDates($eventId) |
||
195 | |||
196 | |||
197 | /** |
||
198 | * @param int $eventId |
||
199 | * @param array $eventDates |
||
200 | * @throws DomainException |
||
201 | * @throws EE_Error |
||
202 | * @throws InvalidArgumentException |
||
203 | * @throws InvalidDataTypeException |
||
204 | * @throws InvalidInterfaceException |
||
205 | * @throws ModelConfigurationException |
||
206 | * @throws ReflectionException |
||
207 | * @throws RestException |
||
208 | * @throws RestPasswordIncorrectException |
||
209 | * @throws RestPasswordRequiredException |
||
210 | * @throws UnexpectedEntityException |
||
211 | * @since $VID:$ |
||
212 | */ |
||
213 | protected function addDefaultEntities($eventId, array $eventDates = []) |
||
232 | |||
233 | |||
234 | /** |
||
235 | * @param int $eventId |
||
236 | * @return array |
||
237 | * @throws EE_Error |
||
238 | * @throws InvalidDataTypeException |
||
239 | * @throws InvalidInterfaceException |
||
240 | * @throws ModelConfigurationException |
||
241 | * @throws RestPasswordIncorrectException |
||
242 | * @throws RestPasswordRequiredException |
||
243 | * @throws UnexpectedEntityException |
||
244 | * @throws RestException |
||
245 | * @throws InvalidArgumentException |
||
246 | * @throws ReflectionException |
||
247 | * @throws DomainException |
||
248 | * @since $VID:$ |
||
249 | */ |
||
250 | protected function getAllEventData($eventId) |
||
375 | } |
||
376 |