Completed
Pull Request — master (#30317)
by Victor
09:41 queued 10s
created

JSResourceLocator::doFind()   D

Complexity

Conditions 10
Paths 8

Size

Total Lines 35
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 24
nc 8
nop 1
dl 0
loc 35
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @author Bart Visscher <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Michael Jobst <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Philipp Schaffrath <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 *
10
 * @copyright Copyright (c) 2018, ownCloud GmbH
11
 * @license AGPL-3.0
12
 *
13
 * This code is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License, version 3,
15
 * as published by the Free Software Foundation.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License, version 3,
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
24
 *
25
 */
26
27
namespace OC\Template;
28
29
class JSResourceLocator extends ResourceLocator {
30
	/**
31
	 * @param string $script
32
	 */
33
	public function doFind($script) {
34
		$themeDirectory = $this->theme->getDirectory();
35
36
		if (strpos($script, '/l10n/') !== false) {
37
			// For language files we try to load them all, so themes can overwrite
38
			// single l10n strings without having to translate all of them.
39
			$found = 0;
40
			$found += $this->appendOnceIfExist($this->serverroot, 'core/'.$script.'.js');
41
			$found += $this->appendOnceIfExist($this->serverroot, $themeDirectory.'/core/'.$script.'.js');
42
			$found += $this->appendOnceIfExist($this->serverroot, $script.'.js');
43
			$found += $this->appendOnceIfExist($this->serverroot, $themeDirectory.'/'.$script.'.js');
44
			$found += $this->appendOnceIfExist($this->serverroot, $themeDirectory.'/apps/'.$script.'.js');
45
46
			if ($found) {
47
				return;
48
			}
49
		} else if ($this->appendOnceIfExist($this->serverroot, $themeDirectory.'/apps/'.$script.'.js')
50
			|| $this->appendOnceIfExist($this->serverroot, $themeDirectory.'/'.$script.'.js')
51
			|| $this->appendOnceIfExist($this->serverroot, $script.'.js')
52
			|| $this->appendOnceIfExist($this->serverroot, $themeDirectory.'/core/'.$script.'.js')
53
			|| $this->appendOnceIfExist($this->serverroot, 'core/'.$script.'.js')
54
		) {
55
			return;
56
		}
57
58
		$app = substr($script, 0, strpos($script, '/'));
59
		$script = substr($script, strpos($script, '/')+1);
60
		$app_path = \OC_App::getAppPath($app);
61
		if( $app_path === false ) { return; }
62
		$app_url = \OC_App::getAppWebPath($app);
63
		$app_url = ($app_url !== false) ? $app_url : null;
64
65
		// missing translations files fill be ignored
66
		$this->appendOnceIfExist($app_path, $script . '.js', $app_url);
67
	}
68
69
	/**
70
	 * @param string $script
71
	 */
72
	public function doFindTheme($script) {
73
	}
74
}
75