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() |
||
| 170 | |||
| 171 | |||
| 172 | /** |
||
| 173 | * @param int $eventId |
||
| 174 | * @return array |
||
| 175 | * @throws DomainException |
||
| 176 | * @throws EE_Error |
||
| 177 | * @throws InvalidArgumentException |
||
| 178 | * @throws InvalidDataTypeException |
||
| 179 | * @throws InvalidInterfaceException |
||
| 180 | * @throws ModelConfigurationException |
||
| 181 | * @throws ReflectionException |
||
| 182 | * @throws RestException |
||
| 183 | * @throws RestPasswordIncorrectException |
||
| 184 | * @throws RestPasswordRequiredException |
||
| 185 | * @throws UnexpectedEntityException |
||
| 186 | * @since $VID:$ |
||
| 187 | */ |
||
| 188 | protected function getEventDates($eventId) |
||
| 200 | |||
| 201 | |||
| 202 | /** |
||
| 203 | * @param int $eventId |
||
| 204 | * @param array $eventDates |
||
| 205 | * @throws DomainException |
||
| 206 | * @throws EE_Error |
||
| 207 | * @throws InvalidArgumentException |
||
| 208 | * @throws InvalidDataTypeException |
||
| 209 | * @throws InvalidInterfaceException |
||
| 210 | * @throws ModelConfigurationException |
||
| 211 | * @throws ReflectionException |
||
| 212 | * @throws RestException |
||
| 213 | * @throws RestPasswordIncorrectException |
||
| 214 | * @throws RestPasswordRequiredException |
||
| 215 | * @throws UnexpectedEntityException |
||
| 216 | * @since $VID:$ |
||
| 217 | */ |
||
| 218 | protected function addDefaultEntities($eventId, array $eventDates = []) |
||
| 237 | |||
| 238 | |||
| 239 | /** |
||
| 240 | * @param int $eventId |
||
| 241 | * @return array |
||
| 242 | * @throws EE_Error |
||
| 243 | * @throws InvalidDataTypeException |
||
| 244 | * @throws InvalidInterfaceException |
||
| 245 | * @throws ModelConfigurationException |
||
| 246 | * @throws RestPasswordIncorrectException |
||
| 247 | * @throws RestPasswordRequiredException |
||
| 248 | * @throws UnexpectedEntityException |
||
| 249 | * @throws RestException |
||
| 250 | * @throws InvalidArgumentException |
||
| 251 | * @throws ReflectionException |
||
| 252 | * @throws DomainException |
||
| 253 | * @since $VID:$ |
||
| 254 | */ |
||
| 255 | protected function getAllEventData($eventId) |
||
| 379 | } |
||
| 380 |