Completed
Push — master ( bcf587...5a9224 )
by Morris
19:50 queued 04:43
created

OC_Defaults   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 288
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 288
rs 8.3396
c 0
b 0
f 0
wmc 44
lcom 1
cbo 7

21 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 30 3
A themeExist() 0 6 3
A getBaseUrl() 0 7 2
A getSyncClientUrl() 0 7 2
A getiOSClientUrl() 0 7 2
A getiTunesAppId() 0 7 2
A getAndroidClientUrl() 0 7 2
A getDocBaseUrl() 0 7 2
A getTitle() 0 7 2
A getName() 0 7 2
A getHTMLName() 0 7 2
A getEntity() 0 7 2
A getSlogan() 0 7 2
A getLogoClaim() 0 7 2
A getShortFooter() 0 11 2
A getLongFooter() 0 9 2
A buildDocLinkToKey() 0 6 2
A getColorPrimary() 0 10 3
A getScssVariables() 0 6 2
A shouldReplaceIcons() 0 3 1
A getLogo() 0 7 2

How to fix   Complexity   

Complex Class

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
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Jan-Christoph Borchardt <[email protected]>
7
 * @author Jörn Friedrich Dreyer <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 * @author Pascal de Bruijn <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Robin McCorkell <[email protected]>
13
 * @author scolebrook <[email protected]>
14
 * @author Thomas Müller <[email protected]>
15
 * @author Volkan Gezer <[email protected]>
16
 *
17
 * @license AGPL-3.0
18
 *
19
 * This code is free software: you can redistribute it and/or modify
20
 * it under the terms of the GNU Affero General Public License, version 3,
21
 * as published by the Free Software Foundation.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
 * GNU Affero General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU Affero General Public License, version 3,
29
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
30
 *
31
 */
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
53
		$this->l = \OC::$server->getL10N('lib');
54
55
		$this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */
56
		$this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */
57
		$this->defaultTitle = 'Nextcloud'; /* can be a longer name, for titles */
58
		$this->defaultBaseUrl = 'https://nextcloud.com';
59
		$this->defaultSyncClientUrl = 'https://nextcloud.com/install/#install-clients';
60
		$this->defaultiOSClientUrl = 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8';
61
		$this->defaultiTunesAppId = '1125420102';
62
		$this->defaultAndroidClientUrl = 'https://play.google.com/store/apps/details?id=com.nextcloud.client';
63
		$this->defaultDocBaseUrl = 'https://docs.nextcloud.com';
64
		$this->defaultDocVersion = '11'; // used to generate doc links
65
		$this->defaultSlogan = $this->l->t('a safe home for all your data');
66
		$this->defaultLogoClaim = '';
67
		$this->defaultColorPrimary = '#0082c9';
68
		$this->defaultLogoUrl = \OC::$server->getURLGenerator()->imagePath('core','logo.svg');
69
		$this->defaultLogoUrl .=  '?v=' . hash('sha1', implode('.', \OCP\Util::getVersion()));
70
71
		$themePath = OC::$SERVERROOT . '/themes/' . OC_Util::getTheme() . '/defaults.php';
72
		if (file_exists($themePath)) {
73
			// prevent defaults.php from printing output
74
			ob_start();
75
			require_once $themePath;
76
			ob_end_clean();
77
			if (class_exists('OC_Theme')) {
78
				$this->theme = new OC_Theme();
79
			}
80
		}
81
	}
82
83
	/**
84
	 * @param string $method
85
	 */
86
	private function themeExist($method) {
87
		if (isset($this->theme) && method_exists($this->theme, $method)) {
88
			return true;
89
		}
90
		return false;
91
	}
92
93
	/**
94
	 * Returns the base URL
95
	 * @return string URL
96
	 */
97
	public function getBaseUrl() {
98
		if ($this->themeExist('getBaseUrl')) {
99
			return $this->theme->getBaseUrl();
100
		} else {
101
			return $this->defaultBaseUrl;
102
		}
103
	}
104
105
	/**
106
	 * Returns the URL where the sync clients are listed
107
	 * @return string URL
108
	 */
109
	public function getSyncClientUrl() {
110
		if ($this->themeExist('getSyncClientUrl')) {
111
			return $this->theme->getSyncClientUrl();
112
		} else {
113
			return $this->defaultSyncClientUrl;
114
		}
115
	}
116
117
	/**
118
	 * Returns the URL to the App Store for the iOS Client
119
	 * @return string URL
120
	 */
121
	public function getiOSClientUrl() {
122
		if ($this->themeExist('getiOSClientUrl')) {
123
			return $this->theme->getiOSClientUrl();
124
		} else {
125
			return $this->defaultiOSClientUrl;
126
		}
127
	}
128
129
	/**
130
	 * Returns the AppId for the App Store for the iOS Client
131
	 * @return string AppId
132
	 */
133
	public function getiTunesAppId() {
134
		if ($this->themeExist('getiTunesAppId')) {
135
			return $this->theme->getiTunesAppId();
136
		} else {
137
			return $this->defaultiTunesAppId;
138
		}
139
	}
140
141
	/**
142
	 * Returns the URL to Google Play for the Android Client
143
	 * @return string URL
144
	 */
145
	public function getAndroidClientUrl() {
146
		if ($this->themeExist('getAndroidClientUrl')) {
147
			return $this->theme->getAndroidClientUrl();
148
		} else {
149
			return $this->defaultAndroidClientUrl;
150
		}
151
	}
152
153
	/**
154
	 * Returns the documentation URL
155
	 * @return string URL
156
	 */
157
	public function getDocBaseUrl() {
158
		if ($this->themeExist('getDocBaseUrl')) {
159
			return $this->theme->getDocBaseUrl();
160
		} else {
161
			return $this->defaultDocBaseUrl;
162
		}
163
	}
164
165
	/**
166
	 * Returns the title
167
	 * @return string title
168
	 */
169
	public function getTitle() {
170
		if ($this->themeExist('getTitle')) {
171
			return $this->theme->getTitle();
172
		} else {
173
			return $this->defaultTitle;
174
		}
175
	}
176
177
	/**
178
	 * Returns the short name of the software
179
	 * @return string title
180
	 */
181
	public function getName() {
182
		if ($this->themeExist('getName')) {
183
			return $this->theme->getName();
184
		} else {
185
			return $this->defaultName;
186
		}
187
	}
188
189
	/**
190
	 * Returns the short name of the software containing HTML strings
191
	 * @return string title
192
	 */
193
	public function getHTMLName() {
194
		if ($this->themeExist('getHTMLName')) {
195
			return $this->theme->getHTMLName();
196
		} else {
197
			return $this->defaultName;
198
		}
199
	}
200
201
	/**
202
	 * Returns entity (e.g. company name) - used for footer, copyright
203
	 * @return string entity name
204
	 */
205
	public function getEntity() {
206
		if ($this->themeExist('getEntity')) {
207
			return $this->theme->getEntity();
208
		} else {
209
			return $this->defaultEntity;
210
		}
211
	}
212
213
	/**
214
	 * Returns slogan
215
	 * @return string slogan
216
	 */
217
	public function getSlogan() {
218
		if ($this->themeExist('getSlogan')) {
219
			return $this->theme->getSlogan();
220
		} else {
221
			return $this->defaultSlogan;
222
		}
223
	}
224
225
	/**
226
	 * Returns logo claim
227
	 * @return string logo claim
228
	 */
229
	public function getLogoClaim() {
230
		if ($this->themeExist('getLogoClaim')) {
231
			return $this->theme->getLogoClaim();
232
		} else {
233
			return $this->defaultLogoClaim;
234
		}
235
	}
236
237
	/**
238
	 * Returns short version of the footer
239
	 * @return string short footer
240
	 */
241
	public function getShortFooter() {
242
		if ($this->themeExist('getShortFooter')) {
243
			$footer = $this->theme->getShortFooter();
244
		} else {
245
			$footer = '<a href="'. $this->getBaseUrl() . '" target="_blank"' .
246
				' rel="noreferrer">' .$this->getEntity() . '</a>'.
247
				' – ' . $this->getSlogan();
248
		}
249
250
		return $footer;
251
	}
252
253
	/**
254
	 * Returns long version of the footer
255
	 * @return string long footer
256
	 */
257
	public function getLongFooter() {
258
		if ($this->themeExist('getLongFooter')) {
259
			$footer = $this->theme->getLongFooter();
260
		} else {
261
			$footer = $this->getShortFooter();
262
		}
263
264
		return $footer;
265
	}
266
267
	/**
268
	 * @param string $key
269
	 * @return string URL to doc with key
270
	 */
271
	public function buildDocLinkToKey($key) {
272
		if ($this->themeExist('buildDocLinkToKey')) {
273
			return $this->theme->buildDocLinkToKey($key);
274
		}
275
		return $this->getDocBaseUrl() . '/server/' . $this->defaultDocVersion . '/go.php?to=' . $key;
276
	}
277
278
	/**
279
	 * Returns primary color
280
	 * @return string
281
	 */
282
	public function getColorPrimary() {
283
284
		if ($this->themeExist('getColorPrimary')) {
285
			return $this->theme->getColorPrimary();
286
		}
287
		if ($this->themeExist('getMailHeaderColor')) {
288
			return $this->theme->getMailHeaderColor();
0 ignored issues
show
Bug introduced by
The method getMailHeaderColor() does not seem to exist on object<OC_Theme>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
289
		}
290
		return $this->defaultColorPrimary;
291
	}
292
293
	/**
294
	 * @return array scss variables to overwrite
295
	 */
296
	public function getScssVariables() {
297
		if($this->themeExist('getScssVariables')) {
298
			return $this->theme->getScssVariables();
299
		}
300
		return [];
301
	}
302
303
	public function shouldReplaceIcons() {
304
		return false;
305
	}
306
307
	/**
308
	 * Themed logo url
309
	 *
310
	 * @return string
311
	 */
312
	public function getLogo() {
313
		if ($this->themeExist('getLogo')) {
314
			return $this->theme->getLogo();
0 ignored issues
show
Bug introduced by
The method getLogo() does not exist on OC_Theme. Did you maybe mean getLogoClaim()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
315
		}
316
317
		return $this->defaultLogoUrl;
318
	}
319
}
320