Complex classes like FileProvider 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 FileProvider, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class FileProvider extends AbstractProvider |
||
11 | { |
||
12 | /** |
||
13 | * @param FormMapper $formMapper |
||
14 | */ |
||
15 | public function buildProviderCreateForm(FormMapper $formMapper) |
||
19 | |||
20 | /** |
||
21 | * @param FormMapper $formMapper |
||
22 | */ |
||
23 | public function buildProviderEditForm(FormMapper $formMapper) |
||
27 | |||
28 | /** |
||
29 | * @param Media $media |
||
30 | */ |
||
31 | public function update(Media $media) |
||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getIcon() |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getTitle() |
||
61 | |||
62 | public function getType() |
||
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getMediaTemplate() |
||
74 | |||
75 | /** |
||
76 | * @param Media $media |
||
77 | */ |
||
78 | protected function setFileImage(Media $media) |
||
96 | |||
97 | /** |
||
98 | * @param $extension |
||
99 | * @return string |
||
100 | */ |
||
101 | protected function getImageByExtension($extension) |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | protected function getImageLocation() |
||
190 | |||
191 | /** |
||
192 | * @return bool |
||
193 | */ |
||
194 | public function supportsDownload() |
||
198 | |||
199 | /** |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function supportsEmbed() |
||
206 | |||
207 | /** |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function supportsImage() |
||
214 | } |
||
215 |