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