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 = []) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Build "Usage" tab |
||
| 39 | * |
||
| 40 | * @param File $record |
||
| 41 | * @param array $context |
||
| 42 | * @return Tab |
||
| 43 | */ |
||
| 44 | protected function getFormFieldUsageTab($record, $context = []) |
||
| 55 | |||
| 56 | protected function getFormFieldDetailsTab($record, $context = []) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Create tab for file attributes |
||
| 81 | * |
||
| 82 | * @param File $record |
||
| 83 | * @param array $context |
||
| 84 | * @return Tab |
||
| 85 | */ |
||
| 86 | protected function getFormFieldAttributesTab($record, $context = []) |
||
| 99 | |||
| 100 | protected function getFormFields(Controller $controller, $name, $context = []) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Get publish action |
||
| 117 | * |
||
| 118 | * @param File $record |
||
| 119 | * @return FormAction |
||
| 120 | */ |
||
| 121 | protected function getPublishAction($record) |
||
| 133 | |||
| 134 | protected function getFormActions(Controller $controller, $name, $context = []) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Get raw HTML for image markup |
||
| 158 | * |
||
| 159 | * @param File $file |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | protected function getIconMarkup($file) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * get HTML for status icon |
||
| 186 | * |
||
| 187 | * @param File $record |
||
| 188 | * @return null|string |
||
| 189 | */ |
||
| 190 | protected function getSpecsMarkup($record) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get published status flag |
||
| 204 | * |
||
| 205 | * @param File $record |
||
| 206 | * @return null|string |
||
| 207 | */ |
||
| 208 | protected function getStatusFlagMarkup($record) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get user-visible "Path" for this record |
||
| 218 | * |
||
| 219 | * @param File $record |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | protected function getPath($record) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get action for adding to campaign |
||
| 236 | * |
||
| 237 | * @param File $record |
||
| 238 | * @return FormAction|null |
||
| 239 | */ |
||
| 240 | protected function getAddToCampaignAction($record) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Get action for publishing |
||
| 253 | * |
||
| 254 | * @param File $record |
||
| 255 | * @return FormAction |
||
| 256 | */ |
||
| 257 | protected function getUnpublishAction($record) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Build popup menu |
||
| 275 | * |
||
| 276 | * @param File $record |
||
| 277 | * @return PopoverField |
||
| 278 | */ |
||
| 279 | protected function getPopoverMenu($record) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @param File $record |
||
| 296 | * @return FormAction |
||
| 297 | */ |
||
| 298 | protected function getInsertAction($record) |
||
| 306 | |||
| 307 | } |
||
| 308 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.