Completed
Push — master ( e1740c...d98dea )
by Morris
14:21
created

CalendarHome::createExtendedCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Georg Ehrke <[email protected]>
6
 * @author Joas Schilling <[email protected]>
7
 * @author Lukas Reschke <[email protected]>
8
 * @author Thomas Müller <[email protected]>
9
 *
10
 * @license AGPL-3.0
11
 *
12
 * This code is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License, version 3,
14
 * as published by the Free Software Foundation.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License, version 3,
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
23
 *
24
 */
25
namespace OCA\DAV\CalDAV;
26
27
use Sabre\CalDAV\Backend\BackendInterface;
28
use Sabre\CalDAV\Backend\NotificationSupport;
29
use Sabre\CalDAV\Backend\SchedulingSupport;
30
use Sabre\CalDAV\Backend\SubscriptionSupport;
31
use Sabre\CalDAV\Schedule\Inbox;
32
use Sabre\CalDAV\Schedule\Outbox;
33
use Sabre\CalDAV\Subscriptions\Subscription;
34
use Sabre\DAV\Exception\NotFound;
35
use Sabre\DAV\Exception\MethodNotAllowed;
36
use Sabre\DAV\MkCol;
37
38
class CalendarHome extends \Sabre\CalDAV\CalendarHome {
39
40
	/** @var \OCP\IL10N */
41
	private $l10n;
42
43
	/** @var \OCP\IConfig */
44
	private $config;
45
46
	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
47
		parent::__construct($caldavBackend, $principalInfo);
48
		$this->l10n = \OC::$server->getL10N('dav');
49
		$this->config = \OC::$server->getConfig();
50
	}
51
52
	/**
53
	 * @return BackendInterface
54
	 */
55
	public function getCalDAVBackend() {
56
		return $this->caldavBackend;
57
	}
58
59
	/**
60
	 * @inheritdoc
61
	 */
62
	function createExtendedCollection($name, MkCol $mkCol) {
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...
63
		$reservedNames = [BirthdayService::BIRTHDAY_CALENDAR_URI];
64
65
		if (in_array($name, $reservedNames)) {
66
			throw new MethodNotAllowed('The resource you tried to create has a reserved name');
67
		}
68
69
		parent::createExtendedCollection($name, $mkCol);
70
	}
71
72
	/**
73
	 * @inheritdoc
74
	 */
75
	function getChildren() {
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...
76
		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
77
		$objects = [];
78
		foreach ($calendars as $calendar) {
79
			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
80
		}
81
82
		if ($this->caldavBackend instanceof SchedulingSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\SchedulingSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
83
			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
84
			$objects[] = new Outbox($this->principalInfo['uri']);
85
		}
86
87
		// We're adding a notifications node, if it's supported by the backend.
88 View Code Duplication
		if ($this->caldavBackend instanceof NotificationSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\NotificationSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
89
			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
90
		}
91
92
		// If the backend supports subscriptions, we'll add those as well,
93 View Code Duplication
		if ($this->caldavBackend instanceof SubscriptionSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\SubscriptionSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
94
			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
95
				$objects[] = new Subscription($this->caldavBackend, $subscription);
96
			}
97
		}
98
99
		return $objects;
100
	}
101
102
	/**
103
	 * @inheritdoc
104
	 */
105
	function getChild($name) {
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...
106
		// Special nodes
107
		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\SchedulingSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
108
			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
109
		}
110
		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\SchedulingSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
111
			return new Outbox($this->principalInfo['uri']);
112
		}
113 View Code Duplication
		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\NotificationSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
114
			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
115
		}
116
117
		// Calendars
118
		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
119
			if ($calendar['uri'] === $name) {
120
				return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config);
121
			}
122
		}
123
124 View Code Duplication
		if ($this->caldavBackend instanceof SubscriptionSupport) {
0 ignored issues
show
Bug introduced by
The class Sabre\CalDAV\Backend\SubscriptionSupport does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
125
			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
126
				if ($subscription['uri'] === $name) {
127
					return new Subscription($this->caldavBackend, $subscription);
128
				}
129
			}
130
131
		}
132
133
		throw new NotFound('Node with name \'' . $name . '\' could not be found');
134
	}
135
136
	/**
137
	 * @param array $filters
138
	 * @param integer|null $limit
139
	 * @param integer|null $offset
140
	 */
141
	function calendarSearch(array $filters, $limit=null, $offset=null) {
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...
142
		$principalUri = $this->principalInfo['uri'];
143
		return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset);
144
	}
145
}
146