Complex classes like OC_Defaults 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 OC_Defaults, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class OC_Defaults { |
||
| 33 | |||
| 34 | private $theme; |
||
| 35 | private $l; |
||
| 36 | |||
| 37 | private $defaultEntity; |
||
| 38 | private $defaultName; |
||
| 39 | private $defaultTitle; |
||
| 40 | private $defaultBaseUrl; |
||
| 41 | private $defaultSyncClientUrl; |
||
| 42 | private $defaultiOSClientUrl; |
||
| 43 | private $defaultiTunesAppId; |
||
| 44 | private $defaultAndroidClientUrl; |
||
| 45 | private $defaultDocBaseUrl; |
||
| 46 | private $defaultDocVersion; |
||
| 47 | private $defaultSlogan; |
||
| 48 | private $defaultLogoClaim; |
||
| 49 | private $defaultColorPrimary; |
||
| 50 | private $defaultLogoUrl; |
||
| 51 | |||
| 52 | function __construct() { |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @param string $method |
||
| 85 | */ |
||
| 86 | private function themeExist($method) { |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Returns the base URL |
||
| 95 | * @return string URL |
||
| 96 | */ |
||
| 97 | public function getBaseUrl() { |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Returns the URL where the sync clients are listed |
||
| 107 | * @return string URL |
||
| 108 | */ |
||
| 109 | public function getSyncClientUrl() { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Returns the URL to the App Store for the iOS Client |
||
| 119 | * @return string URL |
||
| 120 | */ |
||
| 121 | public function getiOSClientUrl() { |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Returns the AppId for the App Store for the iOS Client |
||
| 131 | * @return string AppId |
||
| 132 | */ |
||
| 133 | public function getiTunesAppId() { |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Returns the URL to Google Play for the Android Client |
||
| 143 | * @return string URL |
||
| 144 | */ |
||
| 145 | public function getAndroidClientUrl() { |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Returns the documentation URL |
||
| 155 | * @return string URL |
||
| 156 | */ |
||
| 157 | public function getDocBaseUrl() { |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Returns the title |
||
| 167 | * @return string title |
||
| 168 | */ |
||
| 169 | public function getTitle() { |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Returns the short name of the software |
||
| 179 | * @return string title |
||
| 180 | */ |
||
| 181 | public function getName() { |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Returns the short name of the software containing HTML strings |
||
| 191 | * @return string title |
||
| 192 | */ |
||
| 193 | public function getHTMLName() { |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Returns entity (e.g. company name) - used for footer, copyright |
||
| 203 | * @return string entity name |
||
| 204 | */ |
||
| 205 | public function getEntity() { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Returns slogan |
||
| 215 | * @return string slogan |
||
| 216 | */ |
||
| 217 | public function getSlogan() { |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Returns logo claim |
||
| 227 | * @return string logo claim |
||
| 228 | */ |
||
| 229 | public function getLogoClaim() { |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Returns short version of the footer |
||
| 239 | * @return string short footer |
||
| 240 | */ |
||
| 241 | public function getShortFooter() { |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Returns long version of the footer |
||
| 255 | * @return string long footer |
||
| 256 | */ |
||
| 257 | public function getLongFooter() { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param string $key |
||
| 269 | * @return string URL to doc with key |
||
| 270 | */ |
||
| 271 | public function buildDocLinkToKey($key) { |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Returns primary color |
||
| 280 | * @return string |
||
| 281 | */ |
||
| 282 | public function getColorPrimary() { |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return array scss variables to overwrite |
||
| 295 | */ |
||
| 296 | public function getScssVariables() { |
||
| 302 | |||
| 303 | public function shouldReplaceIcons() { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Themed logo url |
||
| 309 | * |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | public function getLogo() { |
||
| 319 | } |
||
| 320 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.