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 = []) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Create tab for file attributes |
||
| 84 | * |
||
| 85 | * @param File $record |
||
| 86 | * @param array $context |
||
| 87 | * @return Tab |
||
| 88 | */ |
||
| 89 | protected function getFormFieldAttributesTab($record, $context = []) |
||
| 103 | |||
| 104 | protected function getFormFieldHistoryTab($record, $context = []) |
||
| 118 | |||
| 119 | protected function getFormFields(Controller $controller, $name, $context = []) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Get publish action |
||
| 136 | * |
||
| 137 | * @param File $record |
||
| 138 | * @return FormAction |
||
| 139 | */ |
||
| 140 | protected function getPublishAction($record) |
||
| 152 | |||
| 153 | protected function getFormActions(Controller $controller, $name, $context = []) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Get raw HTML for image markup |
||
| 177 | * |
||
| 178 | * @param File $file |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | protected function getIconMarkup($file) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * get HTML for status icon |
||
| 206 | * |
||
| 207 | * @param File $record |
||
| 208 | * @return null|string |
||
| 209 | */ |
||
| 210 | protected function getSpecsMarkup($record) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Get published status flag |
||
| 224 | * |
||
| 225 | * @param File $record |
||
| 226 | * @return null|string |
||
| 227 | */ |
||
| 228 | protected function getStatusFlagMarkup($record) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get user-visible "Path" for this record |
||
| 238 | * |
||
| 239 | * @param File $record |
||
| 240 | * @return string |
||
| 241 | */ |
||
| 242 | protected function getPath($record) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Get action for adding to campaign |
||
| 256 | * |
||
| 257 | * @param File $record |
||
| 258 | * @return FormAction|null |
||
| 259 | */ |
||
| 260 | protected function getAddToCampaignAction($record) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Get action for publishing |
||
| 273 | * |
||
| 274 | * @param File $record |
||
| 275 | * @return FormAction |
||
| 276 | */ |
||
| 277 | protected function getUnpublishAction($record) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Build popup menu |
||
| 295 | * |
||
| 296 | * @param File $record |
||
| 297 | * @return PopoverField |
||
| 298 | */ |
||
| 299 | protected function getPopoverMenu($record) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param File $record |
||
| 316 | * @return FormAction |
||
| 317 | */ |
||
| 318 | protected function getInsertAction($record) |
||
| 326 | } |
||
| 327 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.