Complex classes like Configuration 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 Configuration, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 18 | class Configuration implements LoggerAwareInterface | ||
| 19 | { | ||
| 20 | const DEFAULT_NAME = '_config.yml'; | ||
| 21 | const IMPORT_KEYWORD = 'import'; | ||
| 22 | |||
| 23 | /** | ||
| 24 | * A list of regular expressions or files directly related to stakx websites that should not be copied over to the | ||
| 25 | * compiled website as an asset. | ||
| 26 | * | ||
| 27 | * @var array | ||
| 28 | */ | ||
| 29 |     public static $stakxSourceFiles = array('/^_(?!themes).*/', '/.twig$/'); | ||
| 30 | |||
| 31 | /** | ||
| 32 | * An array representation of the main Yaml configuration. | ||
| 33 | * | ||
| 34 | * @var array | ||
| 35 | */ | ||
| 36 | private $configuration; | ||
| 37 | |||
| 38 | /** | ||
| 39 | * @var string | ||
| 40 | */ | ||
| 41 | private $configFile; | ||
| 42 | |||
| 43 | /** | ||
| 44 | * @var LoggerInterface | ||
| 45 | */ | ||
| 46 | private $output; | ||
| 47 | |||
| 48 | /** | ||
| 49 | * @var Filesystem | ||
| 50 | */ | ||
| 51 | private $fs; | ||
|  | |||
| 52 | |||
| 53 | /** | ||
| 54 | * Configuration constructor. | ||
| 55 | */ | ||
| 56 | 27 | public function __construct() | |
| 61 | |||
| 62 | /** | ||
| 63 | * Parse a given configuration file and configure this Configuration instance. | ||
| 64 | * | ||
| 65 | * This function should be called with 'null' passed when "configuration-less" mode is used | ||
| 66 | * | ||
| 67 | * @param string|null $configFile The path to the configuration file. If null, the default configuration will be | ||
| 68 | * used | ||
| 69 | * @param bool $ignoreDefaults When set to true, the default configuration will not be merged | ||
| 70 | */ | ||
| 71 | 27 | public function parseConfiguration($configFile = null, $ignoreDefaults = false) | |
| 98 | |||
| 99 | /** | ||
| 100 |      * {@inheritdoc} | ||
| 101 | */ | ||
| 102 | 14 | public function setLogger(LoggerInterface $logger) | |
| 106 | |||
| 107 | 14 | public function isDebug() | |
| 111 | |||
| 112 | /** | ||
| 113 | * @TODO 1.0.0 Remove support for 'base' in next major release; it has been replaced by 'baseurl' | ||
| 114 | * | ||
| 115 | * @return string | ||
| 116 | */ | ||
| 117 | 2 | public function getBaseUrl() | |
| 129 | |||
| 130 | /** | ||
| 131 | * @return string[] | ||
| 132 | */ | ||
| 133 | 1 | public function getDataFolders() | |
| 137 | |||
| 138 | /** | ||
| 139 | * @return string[] | ||
| 140 | */ | ||
| 141 | 1 | public function getDataSets() | |
| 145 | |||
| 146 | 1 | public function getIncludes() | |
| 150 | |||
| 151 | 1 | public function getExcludes() | |
| 155 | |||
| 156 | 14 | public function getTheme() | |
| 160 | |||
| 161 | 1 | public function getConfiguration() | |
| 165 | |||
| 166 | 1 | public function getPageViewFolders() | |
| 170 | |||
| 171 | 2 | public function getTargetFolder() | |
| 175 | |||
| 176 | 1 | public function getCollectionsFolders() | |
| 180 | |||
| 181 | 14 | public function getTwigAutoescape() | |
| 185 | |||
| 186 | /** | ||
| 187 | * @return string|false | ||
| 188 | */ | ||
| 189 | public function getRedirectTemplate() | ||
| 193 | |||
| 194 | /** | ||
| 195 | * Return the specified configuration option if available, otherwise return the default. | ||
| 196 | * | ||
| 197 | * @param string $name The configuration option to lookup | ||
| 198 | * @param mixed|null $default The default value returned if the configuration option isn't found | ||
| 199 | * | ||
| 200 | * @return mixed|null | ||
| 201 | */ | ||
| 202 | 27 | private function returnConfigOption($name, $default = null) | |
| 206 | |||
| 207 | 27 | private function mergeDefaultConfiguration() | |
| 230 | |||
| 231 | 27 | private function handleDeprecations() | |
| 241 | |||
| 242 | 14 | private function handleImports() | |
| 284 | |||
| 285 | /** | ||
| 286 | * Check whether a given file path is a valid import | ||
| 287 | * | ||
| 288 | * @param string $filePath | ||
| 289 | * | ||
| 290 | * @return bool | ||
| 291 | */ | ||
| 292 | private function configImportIsValid($filePath) | ||
| 325 | |||
| 326 | /** | ||
| 327 | * Import a given configuration to be merged with the parent configuration | ||
| 328 | * | ||
| 329 | * @param string $filePath | ||
| 330 | * | ||
| 331 | * @return Configuration | ||
| 332 | */ | ||
| 333 | private function parseOther($filePath) | ||
| 341 | |||
| 342 | /** | ||
| 343 | * Merge the given array with existing configuration | ||
| 344 | * | ||
| 345 | * @param array $importedConfig | ||
| 346 | */ | ||
| 347 | private function mergeImports(array $importedConfig) | ||
| 355 | } | ||
| 356 | 
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.