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 |
||
| 22 | class Config implements ConfigInterface |
||
| 23 | { |
||
| 24 | protected $currentDir; |
||
| 25 | protected $cacheDir; |
||
| 26 | protected $installDir; |
||
| 27 | protected $filesystem; |
||
| 28 | protected $basePackagesUrl = 'http://bower.herokuapp.com/packages/'; |
||
| 29 | protected $allPackagesUrl = 'https://bower-component-list.herokuapp.com/'; |
||
| 30 | protected $saveToBowerJsonFile = false; |
||
| 31 | protected $bowerFileNames = array('bower.json', 'package.json'); |
||
| 32 | protected $stdBowerFileName = 'bower.json'; |
||
| 33 | protected $rcFileName = '.bowerrc'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param Filesystem $filesystem |
||
| 37 | */ |
||
| 38 | public function __construct(Filesystem $filesystem) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | public function getCurrentDir() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | public function getBasePackagesUrl() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | public function getAllPackagesUrl() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | public function getCacheDir() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * {@inheritdoc} |
||
| 98 | */ |
||
| 99 | public function getInstallDir() |
||
| 103 | |||
| 104 | /** |
||
| 105 | * {@inheritdoc} |
||
| 106 | */ |
||
| 107 | public function isSaveToBowerJsonFile() |
||
| 111 | |||
| 112 | /** |
||
| 113 | * {@inheritdoc} |
||
| 114 | */ |
||
| 115 | public function setSaveToBowerJsonFile($flag = true) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | public function initBowerJsonFile(array $params) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * {@inheritdoc} |
||
| 133 | */ |
||
| 134 | public function updateBowerJsonFile(PackageInterface $package) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | public function updateBowerJsonFile2(array $old, array $new) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * {@inheritdoc} |
||
| 161 | */ |
||
| 162 | public function getBowerFileContent() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * {@inheritdoc} |
||
| 177 | */ |
||
| 178 | public function getOverridesSection() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * {@inheritdoc} |
||
| 192 | */ |
||
| 193 | public function getOverrideFor($packageName) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * {@inheritdoc} |
||
| 205 | */ |
||
| 206 | public function getPackageBowerFileContent(PackageInterface $package) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * {@inheritdoc} |
||
| 223 | */ |
||
| 224 | public function bowerFileExists() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param array $params |
||
| 231 | * @return array |
||
| 232 | */ |
||
| 233 | protected function createAClearBowerFile(array $params) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | protected function getHomeDir() |
||
| 268 | |||
| 269 | protected function getBowerrcPath() |
||
| 280 | } |
||
| 281 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: