Complex classes like FileFormFactory 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 FileFormFactory, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class FileFormFactory extends AssetFormFactory |
||
| 18 | { |
||
| 19 | protected function getFormFieldTabs($record, $context = []) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Build "Usage" tab |
||
| 40 | * |
||
| 41 | * @param File $record |
||
| 42 | * @param array $context |
||
| 43 | * @return Tab |
||
| 44 | */ |
||
| 45 | protected function getFormFieldUsageTab($record, $context = []) |
||
| 56 | |||
| 57 | protected function getFormFieldDetailsTab($record, $context = []) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Create tab for file attributes |
||
| 82 | * |
||
| 83 | * @param File $record |
||
| 84 | * @param array $context |
||
| 85 | * @return Tab |
||
| 86 | */ |
||
| 87 | protected function getFormFieldAttributesTab($record, $context = []) |
||
| 100 | |||
| 101 | protected function getFormFieldHistoryTab($record, $context = []) |
||
| 115 | |||
| 116 | protected function getFormFields(Controller $controller, $name, $context = []) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Get publish action |
||
| 133 | * |
||
| 134 | * @param File $record |
||
| 135 | * @return FormAction |
||
| 136 | */ |
||
| 137 | protected function getPublishAction($record) |
||
| 149 | |||
| 150 | protected function getFormActions(Controller $controller, $name, $context = []) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Get raw HTML for image markup |
||
| 174 | * |
||
| 175 | * @param File $file |
||
| 176 | * @return string |
||
| 177 | */ |
||
| 178 | protected function getIconMarkup($file) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * get HTML for status icon |
||
| 202 | * |
||
| 203 | * @param File $record |
||
| 204 | * @return null|string |
||
| 205 | */ |
||
| 206 | protected function getSpecsMarkup($record) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Get published status flag |
||
| 220 | * |
||
| 221 | * @param File $record |
||
| 222 | * @return null|string |
||
| 223 | */ |
||
| 224 | protected function getStatusFlagMarkup($record) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get user-visible "Path" for this record |
||
| 234 | * |
||
| 235 | * @param File $record |
||
| 236 | * @return string |
||
| 237 | */ |
||
| 238 | protected function getPath($record) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Get action for adding to campaign |
||
| 252 | * |
||
| 253 | * @param File $record |
||
| 254 | * @return FormAction|null |
||
| 255 | */ |
||
| 256 | protected function getAddToCampaignAction($record) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Get action for publishing |
||
| 269 | * |
||
| 270 | * @param File $record |
||
| 271 | * @return FormAction |
||
| 272 | */ |
||
| 273 | protected function getUnpublishAction($record) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Build popup menu |
||
| 291 | * |
||
| 292 | * @param File $record |
||
| 293 | * @return PopoverField |
||
| 294 | */ |
||
| 295 | protected function getPopoverMenu($record) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @param File $record |
||
| 312 | * @return FormAction |
||
| 313 | */ |
||
| 314 | protected function getInsertAction($record) |
||
| 322 | |||
| 323 | } |
||
| 324 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.