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 | private $defaultCacheBuster; |
||
|
|
|||
| 52 | |||
| 53 | function __construct() { |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $method |
||
| 86 | */ |
||
| 87 | private function themeExist($method) { |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Returns the base URL |
||
| 96 | * @return string URL |
||
| 97 | */ |
||
| 98 | public function getBaseUrl() { |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Returns the URL where the sync clients are listed |
||
| 108 | * @return string URL |
||
| 109 | */ |
||
| 110 | public function getSyncClientUrl() { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Returns the URL to the App Store for the iOS Client |
||
| 120 | * @return string URL |
||
| 121 | */ |
||
| 122 | public function getiOSClientUrl() { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Returns the AppId for the App Store for the iOS Client |
||
| 132 | * @return string AppId |
||
| 133 | */ |
||
| 134 | public function getiTunesAppId() { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Returns the URL to Google Play for the Android Client |
||
| 144 | * @return string URL |
||
| 145 | */ |
||
| 146 | public function getAndroidClientUrl() { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Returns the documentation URL |
||
| 156 | * @return string URL |
||
| 157 | */ |
||
| 158 | public function getDocBaseUrl() { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Returns the title |
||
| 168 | * @return string title |
||
| 169 | */ |
||
| 170 | public function getTitle() { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Returns the short name of the software |
||
| 180 | * @return string title |
||
| 181 | */ |
||
| 182 | public function getName() { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Returns the short name of the software containing HTML strings |
||
| 192 | * @return string title |
||
| 193 | */ |
||
| 194 | public function getHTMLName() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Returns entity (e.g. company name) - used for footer, copyright |
||
| 204 | * @return string entity name |
||
| 205 | */ |
||
| 206 | public function getEntity() { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Returns slogan |
||
| 216 | * @return string slogan |
||
| 217 | */ |
||
| 218 | public function getSlogan() { |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Returns logo claim |
||
| 228 | * @return string logo claim |
||
| 229 | */ |
||
| 230 | public function getLogoClaim() { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Returns short version of the footer |
||
| 240 | * @return string short footer |
||
| 241 | */ |
||
| 242 | public function getShortFooter() { |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Returns long version of the footer |
||
| 256 | * @return string long footer |
||
| 257 | */ |
||
| 258 | public function getLongFooter() { |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param string $key |
||
| 270 | * @return string URL to doc with key |
||
| 271 | */ |
||
| 272 | public function buildDocLinkToKey($key) { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Returns primary color |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function getColorPrimary() { |
||
| 293 | |||
| 294 | public function shouldReplaceIcons() { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Themed logo url |
||
| 300 | * |
||
| 301 | * @return string |
||
| 302 | */ |
||
| 303 | public function getLogo() { |
||
| 310 | } |
||
| 311 |
This check marks private properties in classes that are never used. Those properties can be removed.