Completed
Pull Request — master (#377)
by Victor
05:44
created

DocLink::trimVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
/**
3
 * @author Victor Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2015, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace Owncloud\Updater\Utils;
23
24
use Owncloud\Updater\Utils\OccRunner;
25
26
class DocLink {
27
28
	const BASE_DOC_URL = 'https://doc.owncloud.org/server';
29
30
	private $version;
31
32
	/**
33
	 * DocLink constructor.
34
	 *
35
	 * @param string $version
36
	 */
37 4
	public function __construct($version) {
38 4
		$this->version = $this->trimVersion($version);
39 4
	}
40
41
	/**
42
	 * Cut everything except Major.Minor
43
	 * @param string $version
44
	 * @return string
45
	 */
46 4
	protected function trimVersion($version){
47 4
		if (preg_match('|^\d+\.\d+|', $version, $matches)>0){
48 4
			return $matches[0];
49
		}
50
		return '';
51
	}
52
53
	/**
54
	 * @param string $relativePart
55
	 * @return string
56
	 */
57 4
	public function getAdminManualUrl($relativePart){
58 4
		return sprintf(
59 4
			'%s/%s/admin_manual/%s',
60 4
			self::BASE_DOC_URL,
61 4
			$this->version,
62
			$relativePart
63
		);
64
	}
65
}
66