Complex classes like Config 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.
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 Config, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Config implements ConfigInterface |
||
22 | { |
||
23 | protected $cacheDir; |
||
24 | protected $installDir; |
||
25 | protected $filesystem; |
||
26 | protected $basePackagesUrl = 'http://bower.herokuapp.com/packages/'; |
||
27 | protected $allPackagesUrl = 'https://bower-component-list.herokuapp.com/'; |
||
28 | protected $saveToBowerJsonFile = false; |
||
29 | protected $bowerFileNames = ['bower.json', 'package.json']; |
||
30 | protected $stdBowerFileName = 'bower.json'; |
||
31 | protected $scripts = ['preinstall'=>[],'postinstall'=>[],'preuninstall'=>[]]; |
||
32 | |||
33 | /** |
||
34 | * @param Filesystem $filesystem |
||
35 | */ |
||
36 | public function __construct(Filesystem $filesystem) |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function getScripts() |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function getBasePackagesUrl() |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function getAllPackagesUrl() |
||
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | public function getCacheDir() |
||
105 | |||
106 | /** |
||
107 | * {@inheritdoc} |
||
108 | */ |
||
109 | public function getInstallDir() |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function isSaveToBowerJsonFile() |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function setSaveToBowerJsonFile($flag = true) |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function initBowerJsonFile(array $params) |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function updateBowerJsonFile(PackageInterface $package) |
||
157 | |||
158 | /** |
||
159 | * {@inheritdoc} |
||
160 | */ |
||
161 | public function updateBowerJsonFile2(array $old, array $new) |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function getBowerFileContent() |
||
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function getOverridesSection() |
||
199 | |||
200 | /** |
||
201 | * {@inheritdoc} |
||
202 | */ |
||
203 | public function getOverrideFor($packageName) |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | public function getPackageBowerFileContent(PackageInterface $package) |
||
230 | |||
231 | /** |
||
232 | * {@inheritdoc} |
||
233 | */ |
||
234 | public function bowerFileExists() |
||
238 | |||
239 | /** |
||
240 | * @param array $params |
||
241 | * @return array |
||
242 | */ |
||
243 | protected function createAClearBowerFile(array $params) |
||
257 | |||
258 | /** |
||
259 | * @return string |
||
260 | */ |
||
261 | protected function getHomeDir() |
||
278 | } |
||
279 |
A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.
You can also find more information in the “Code” section of your repository.