Complex classes like GlobalConfig 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 GlobalConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class GlobalConfig extends BaseConfig { |
||
| 17 | |||
| 18 | /** Cache reference */ |
||
| 19 | private $cache; |
||
| 20 | /** Location of the configuration file. Used for caching. */ |
||
| 21 | private $filePath; |
||
| 22 | /** Namespaces from vocabularies configuration file. */ |
||
| 23 | private $namespaces; |
||
| 24 | /** EasyRdf\Graph graph */ |
||
| 25 | private $graph; |
||
| 26 | /** |
||
| 27 | * @var int the time the config file was last modified |
||
| 28 | */ |
||
| 29 | private $configModifiedTime = null; |
||
| 30 | |||
| 31 | public function __construct($config_name='/../config.ttl') |
||
| 45 | |||
| 46 | public function getCache() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return int the time the config file was last modified |
||
| 53 | */ |
||
| 54 | public function getConfigModifiedTime() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Initialize configuration, reading the configuration file from the disk, |
||
| 61 | * and creating the graph and resources objects. Uses a cache if available, |
||
| 62 | * in order to avoid re-loading the complete configuration on each request. |
||
| 63 | */ |
||
| 64 | private function initializeConfig() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Parses configuration from the config.ttl file |
||
| 103 | * @param string $filename path to config.ttl file |
||
| 104 | * @throws \EasyRdf\Exception |
||
| 105 | */ |
||
| 106 | private function parseConfig($filename) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Returns the graph created after parsing the configuration file. |
||
| 116 | * @return \EasyRdf\Graph |
||
| 117 | */ |
||
| 118 | public function getGraph() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Registers RDF namespaces from the config.ttl file for use by EasyRdf (e.g. serializing) |
||
| 125 | */ |
||
| 126 | private function initializeNamespaces() { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Returns the UI languages specified in the configuration or defaults to |
||
| 137 | * only show English |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | public function getLanguages() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Returns the external HTTP request timeout in seconds or the default value |
||
| 162 | * of 5 seconds if not specified in the configuration. |
||
| 163 | * @return integer |
||
| 164 | */ |
||
| 165 | public function getHttpTimeout() |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Returns the SPARQL HTTP request timeout in seconds or the default value |
||
| 172 | * of 20 seconds if not specified in the configuration. |
||
| 173 | * @return integer |
||
| 174 | */ |
||
| 175 | public function getSparqlTimeout() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Returns the sparql endpoint address defined in the configuration. If |
||
| 182 | * not then defaulting to http://localhost:3030/ds/sparql |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function getDefaultEndpoint() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Returns the maximum number of items to return in transitive queries if defined |
||
| 197 | * in the configuration or the default value of 1000. |
||
| 198 | * @return integer |
||
| 199 | */ |
||
| 200 | public function getDefaultTransitiveLimit() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Returns the maximum number of items to load at a time if defined |
||
| 207 | * in the configuration or the default value of 20. |
||
| 208 | * @return integer |
||
| 209 | */ |
||
| 210 | public function getSearchResultsSize() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Returns the configured location for the twig template cache and if not |
||
| 217 | * defined defaults to "/tmp/skosmos-template-cache" |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | public function getTemplateCache() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Returns the defined sparql-query extension eg. "JenaText" or |
||
| 227 | * if not defined falling back to SPARQL 1.1 |
||
| 228 | * @return string |
||
| 229 | */ |
||
| 230 | public function getDefaultSparqlDialect() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Returns the feedback address defined in the configuration. |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | public function getFeedbackAddress() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Returns the feedback sender address defined in the configuration. |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | public function getFeedbackSender() |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Returns the feedback envelope sender address defined in the configuration. |
||
| 255 | * @return string |
||
| 256 | */ |
||
| 257 | public function getFeedbackEnvelopeSender() |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Returns true if exception logging has been configured. |
||
| 264 | * @return boolean |
||
| 265 | */ |
||
| 266 | public function getLogCaughtExceptions() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Returns true if browser console logging has been enabled, |
||
| 273 | * @return boolean |
||
| 274 | */ |
||
| 275 | public function getLoggingBrowserConsole() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Returns the name of a log file if configured, or NULL otherwise. |
||
| 282 | * @return string |
||
| 283 | */ |
||
| 284 | public function getLoggingFilename() |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public function getServiceName() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @return string |
||
| 299 | */ |
||
| 300 | public function getCustomCss() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @return boolean |
||
| 307 | */ |
||
| 308 | public function getUiLanguageDropdown() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @return string |
||
| 315 | */ |
||
| 316 | public function getBaseHref() |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @return array |
||
| 323 | */ |
||
| 324 | public function getGlobalPlugins() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @return boolean |
||
| 338 | */ |
||
| 339 | public function getHoneypotEnabled() |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @return integer |
||
| 346 | */ |
||
| 347 | public function getHoneypotTime() |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return boolean |
||
| 354 | */ |
||
| 355 | public function getCollationEnabled() |
||
| 359 | } |
||
| 360 |