Plugin   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCalendarHomeForPrincipal() 0 12 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud GmbH.
4
 *
5
 * @author Christoph Wurst <[email protected]>
6
 * @author Georg Ehrke <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program. If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
namespace OCA\DAV\CalDAV;
25
26
class Plugin extends \Sabre\CalDAV\Plugin {
27
	public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
28
29
	/**
30
	 * Returns the path to a principal's calendar home.
31
	 *
32
	 * The return url must not end with a slash.
33
	 * This function should return null in case a principal did not have
34
	 * a calendar home.
35
	 *
36
	 * @param string $principalUrl
37
	 * @return string|null
38
	 */
39
	public function getCalendarHomeForPrincipal($principalUrl) {
40
		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
41
			[, $principalId] = \Sabre\Uri\split($principalUrl);
42
			return self::CALENDAR_ROOT . '/' . $principalId;
43
		}
44
		if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
45
			[, $principalId] = \Sabre\Uri\split($principalUrl);
46
			return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
47
		}
48
		if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
49
			[, $principalId] = \Sabre\Uri\split($principalUrl);
50
			return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
51
		}
52
	}
53
}
54