Completed
Push — master ( ab4fd5...664d98 )
by Victor
20:52 queued 01:47
created

CSSResourceLocator::doFind()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 4
nop 1
dl 0
loc 17
rs 8.8571
c 0
b 0
f 0
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 CSSResourceLocator extends ResourceLocator {
30
	/**
31
	 * @param string $style
32
	 */
33
	public function doFind($style) {
34
		$fullStyle = $this->addExtension($style);
35
		if (
36
			$this->appendOnceIfExist($this->serverroot, $fullStyle)
37
			|| $this->appendOnceIfExist($this->serverroot, 'core/' . $fullStyle)
38
		) {
39
			return;
40
		}
41
		$app = substr($fullStyle, 0, strpos($fullStyle, '/'));
42
		$fullStyle = substr($fullStyle, strpos($fullStyle, '/')+1);
43
44
		$app_path = $this->appManager->getAppPath($app);
45
		if( $app_path === false ) { return; }
46
		$app_url = $this->appManager->getAppWebPath($app);
47
		$app_url = ($app_url !== false) ? $app_url : null;
48
		$this->appendOnceIfExist($app_path, $fullStyle, $app_url);
49
	}
50
51
	/**
52
	 * @param string $style
53
	 */
54
	public function doFindTheme($style) {
55
		$fullStyle = $this->addExtension($style);
56
		$themeDirectory = $this->theme->getDirectory();
57
		$baseDirectory = $this->theme->getBaseDirectory();
58
		$webRoot = '';
59 View Code Duplication
		if ($baseDirectory !== $this->serverroot) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
			$webRoot = substr($this->theme->getWebPath(), 0, -strlen($themeDirectory));
61
		}
62
63
		$searchLocations = [
64
			$this->buildPath([$themeDirectory, 'apps', $fullStyle]),
65
			$this->buildPath([$themeDirectory, $fullStyle]),
66
			$this->buildPath([$themeDirectory, 'core', $fullStyle]),
67
		];
68
69
		foreach ($searchLocations as $location) {
70
			if ($this->appendOnceIfExist($baseDirectory, $location, $webRoot)) {
71
				break;
72
			}
73
		}
74
	}
75
76
	/**
77
	 * @param string $path
78
	 * @return string
79
	 */
80
	protected function addExtension($path) {
81
		return $path . '.css';
82
	}
83
}
84