| Total Complexity | 50 |
| Total Lines | 307 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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.
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 |
||
| 40 | class OC_Defaults { |
||
| 41 | private $theme; |
||
| 42 | |||
| 43 | private $defaultEntity; |
||
| 44 | private $defaultName; |
||
| 45 | private $defaultTitle; |
||
| 46 | private $defaultBaseUrl; |
||
| 47 | private $defaultSyncClientUrl; |
||
| 48 | private $defaultiOSClientUrl; |
||
| 49 | private $defaultiTunesAppId; |
||
| 50 | private $defaultAndroidClientUrl; |
||
| 51 | private $defaultFDroidClientUrl; |
||
| 52 | private $defaultDocBaseUrl; |
||
| 53 | private $defaultDocVersion; |
||
| 54 | private $defaultSlogan; |
||
| 55 | private $defaultColorPrimary; |
||
| 56 | private $defaultTextColorPrimary; |
||
| 57 | private $defaultProductName; |
||
| 58 | |||
| 59 | public function __construct() { |
||
| 60 | $config = \OC::$server->getConfig(); |
||
| 61 | |||
| 62 | $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ |
||
| 63 | $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ |
||
| 64 | $this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */ |
||
| 65 | $this->defaultBaseUrl = 'https://nextcloud.com'; |
||
| 66 | $this->defaultSyncClientUrl = $config->getSystemValue('customclient_desktop', 'https://nextcloud.com/install/#install-clients'); |
||
| 67 | $this->defaultiOSClientUrl = $config->getSystemValue('customclient_ios', 'https://geo.itunes.apple.com/us/app/nextcloud/id1125420102?mt=8'); |
||
| 68 | $this->defaultiTunesAppId = $config->getSystemValue('customclient_ios_appid', '1125420102'); |
||
| 69 | $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); |
||
| 70 | $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/'); |
||
| 71 | $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; |
||
| 72 | $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links |
||
| 73 | $this->defaultColorPrimary = '#0082c9'; |
||
| 74 | $this->defaultTextColorPrimary = '#ffffff'; |
||
| 75 | $this->defaultProductName = 'Nextcloud'; |
||
| 76 | |||
| 77 | $themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php'; |
||
| 78 | if (file_exists($themePath)) { |
||
| 79 | // prevent defaults.php from printing output |
||
| 80 | ob_start(); |
||
| 81 | require_once $themePath; |
||
| 82 | ob_end_clean(); |
||
| 83 | if (class_exists('OC_Theme')) { |
||
| 84 | $this->theme = new OC_Theme(); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @param string $method |
||
| 91 | */ |
||
| 92 | private function themeExist($method) { |
||
| 93 | if (isset($this->theme) && method_exists($this->theme, $method)) { |
||
| 94 | return true; |
||
| 95 | } |
||
| 96 | return false; |
||
| 97 | } |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Returns the base URL |
||
| 101 | * @return string URL |
||
| 102 | */ |
||
| 103 | public function getBaseUrl() { |
||
| 104 | if ($this->themeExist('getBaseUrl')) { |
||
| 105 | return $this->theme->getBaseUrl(); |
||
| 106 | } else { |
||
| 107 | return $this->defaultBaseUrl; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Returns the URL where the sync clients are listed |
||
| 113 | * @return string URL |
||
| 114 | */ |
||
| 115 | public function getSyncClientUrl() { |
||
| 116 | if ($this->themeExist('getSyncClientUrl')) { |
||
| 117 | return $this->theme->getSyncClientUrl(); |
||
| 118 | } else { |
||
| 119 | return $this->defaultSyncClientUrl; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Returns the URL to the App Store for the iOS Client |
||
| 125 | * @return string URL |
||
| 126 | */ |
||
| 127 | public function getiOSClientUrl() { |
||
| 128 | if ($this->themeExist('getiOSClientUrl')) { |
||
| 129 | return $this->theme->getiOSClientUrl(); |
||
| 130 | } else { |
||
| 131 | return $this->defaultiOSClientUrl; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Returns the AppId for the App Store for the iOS Client |
||
| 137 | * @return string AppId |
||
| 138 | */ |
||
| 139 | public function getiTunesAppId() { |
||
| 140 | if ($this->themeExist('getiTunesAppId')) { |
||
| 141 | return $this->theme->getiTunesAppId(); |
||
| 142 | } else { |
||
| 143 | return $this->defaultiTunesAppId; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Returns the URL to Google Play for the Android Client |
||
| 149 | * @return string URL |
||
| 150 | */ |
||
| 151 | public function getAndroidClientUrl() { |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Returns the URL to Google Play for the Android Client |
||
| 161 | * @return string URL |
||
| 162 | */ |
||
| 163 | public function getFDroidClientUrl() { |
||
| 164 | if ($this->themeExist('getFDroidClientUrl')) { |
||
| 165 | return $this->theme->getFDroidClientUrl(); |
||
| 166 | } else { |
||
| 167 | return $this->defaultFDroidClientUrl; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Returns the documentation URL |
||
| 173 | * @return string URL |
||
| 174 | */ |
||
| 175 | public function getDocBaseUrl() { |
||
| 176 | if ($this->themeExist('getDocBaseUrl')) { |
||
| 177 | return $this->theme->getDocBaseUrl(); |
||
| 178 | } else { |
||
| 179 | return $this->defaultDocBaseUrl; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Returns the title |
||
| 185 | * @return string title |
||
| 186 | */ |
||
| 187 | public function getTitle() { |
||
| 188 | if ($this->themeExist('getTitle')) { |
||
| 189 | return $this->theme->getTitle(); |
||
| 190 | } else { |
||
| 191 | return $this->defaultTitle; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Returns the short name of the software |
||
| 197 | * @return string title |
||
| 198 | */ |
||
| 199 | public function getName() { |
||
| 204 | } |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Returns the short name of the software containing HTML strings |
||
| 209 | * @return string title |
||
| 210 | */ |
||
| 211 | public function getHTMLName() { |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Returns entity (e.g. company name) - used for footer, copyright |
||
| 221 | * @return string entity name |
||
| 222 | */ |
||
| 223 | public function getEntity() { |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Returns slogan |
||
| 233 | * @return string slogan |
||
| 234 | */ |
||
| 235 | public function getSlogan(?string $lang = null) { |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Returns short version of the footer |
||
| 249 | * @return string short footer |
||
| 250 | */ |
||
| 251 | public function getShortFooter() { |
||
| 252 | if ($this->themeExist('getShortFooter')) { |
||
| 253 | $footer = $this->theme->getShortFooter(); |
||
| 254 | } else { |
||
| 255 | $footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' . |
||
| 256 | ' rel="noreferrer noopener">' .$this->getEntity() . '</a>'. |
||
| 257 | ' – ' . $this->getSlogan(); |
||
| 258 | } |
||
| 259 | |||
| 260 | return $footer; |
||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Returns long version of the footer |
||
| 265 | * @return string long footer |
||
| 266 | */ |
||
| 267 | public function getLongFooter() { |
||
| 268 | if ($this->themeExist('getLongFooter')) { |
||
| 269 | $footer = $this->theme->getLongFooter(); |
||
| 270 | } else { |
||
| 271 | $footer = $this->getShortFooter(); |
||
| 272 | } |
||
| 273 | |||
| 274 | return $footer; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param string $key |
||
| 279 | * @return string URL to doc with key |
||
| 280 | */ |
||
| 281 | public function buildDocLinkToKey($key) { |
||
| 282 | if ($this->themeExist('buildDocLinkToKey')) { |
||
| 283 | return $this->theme->buildDocLinkToKey($key); |
||
| 284 | } |
||
| 285 | return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key; |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Returns primary color |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public function getColorPrimary() { |
||
| 293 | if ($this->themeExist('getColorPrimary')) { |
||
| 294 | return $this->theme->getColorPrimary(); |
||
| 295 | } |
||
| 296 | if ($this->themeExist('getMailHeaderColor')) { |
||
| 297 | return $this->theme->getMailHeaderColor(); |
||
| 298 | } |
||
| 299 | return $this->defaultColorPrimary; |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @return array scss variables to overwrite |
||
| 304 | */ |
||
| 305 | public function getScssVariables() { |
||
| 310 | } |
||
| 311 | |||
| 312 | public function shouldReplaceIcons() { |
||
| 313 | return false; |
||
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Themed logo url |
||
| 318 | * |
||
| 319 | * @param bool $useSvg Whether to point to the SVG image or a fallback |
||
| 320 | * @return string |
||
| 321 | */ |
||
| 322 | public function getLogo($useSvg = true) { |
||
| 323 | if ($this->themeExist('getLogo')) { |
||
| 324 | return $this->theme->getLogo($useSvg); |
||
| 325 | } |
||
| 326 | |||
| 327 | if ($useSvg) { |
||
| 328 | $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.svg'); |
||
| 329 | } else { |
||
| 330 | $logo = \OC::$server->getURLGenerator()->imagePath('core', 'logo/logo.png'); |
||
| 331 | } |
||
| 332 | return $logo . '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion())); |
||
| 333 | } |
||
| 334 | |||
| 335 | public function getTextColorPrimary() { |
||
| 336 | if ($this->themeExist('getTextColorPrimary')) { |
||
| 337 | return $this->theme->getTextColorPrimary(); |
||
| 338 | } |
||
| 339 | return $this->defaultTextColorPrimary; |
||
| 340 | } |
||
| 341 | |||
| 342 | public function getProductName() { |
||
| 347 | } |
||
| 348 | } |
||
| 349 |