Passed
Push — master ( 25fe32...0fb74a )
by Morris
13:02 queued 10s
created

CachedSubscription::createFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright 2018 Georg Ehrke <[email protected]>
5
 *
6
 * @author Georg Ehrke <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
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
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OCA\DAV\CalDAV;
25
26
use Sabre\CalDAV\Backend\BackendInterface;
27
use Sabre\DAV\Exception\MethodNotAllowed;
28
use Sabre\DAV\Exception\NotFound;
29
use Sabre\DAV\PropPatch;
30
31
/**
32
 * Class CachedSubscription
33
 *
34
 * @package OCA\DAV\CalDAV
35
 * @property BackendInterface|CalDavBackend $caldavBackend
36
 */
37
class CachedSubscription extends \Sabre\CalDAV\Calendar {
38
39
	/**
40
	 * @return string
41
	 */
42
	public function getPrincipalURI():string {
43
		return $this->calendarInfo['principaluri'];
44
	}
45
46
	/**
47
	 * @return array
48
	 */
49
	public function getACL():array {
50
		return [
51
			[
52
				'privilege' => '{DAV:}read',
53
				'principal' => $this->getOwner(),
54
				'protected' => true,
55
			],
56
			[
57
				'privilege' => '{DAV:}read',
58
				'principal' => $this->getOwner() . '/calendar-proxy-write',
59
				'protected' => true,
60
			],
61
			[
62
				'privilege' => '{DAV:}read',
63
				'principal' => $this->getOwner() . '/calendar-proxy-read',
64
				'protected' => true,
65
			],
66
			[
67
				'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
68
				'principal' => '{DAV:}authenticated',
69
				'protected' => true,
70
			],
71
		];
72
	}
73
74
	/**
75
	 * @return array
76
	 */
77
	public function getChildACL():array {
78
		return [
79
			[
80
				'privilege' => '{DAV:}read',
81
				'principal' => $this->getOwner(),
82
				'protected' => true,
83
			],
84
85
			[
86
				'privilege' => '{DAV:}read',
87
				'principal' => $this->getOwner() . '/calendar-proxy-write',
88
				'protected' => true,
89
			],
90
			[
91
				'privilege' => '{DAV:}read',
92
				'principal' => $this->getOwner() . '/calendar-proxy-read',
93
				'protected' => true,
94
			],
95
96
		];
97
	}
98
99
	/**
100
	 * @return null|string
101
	 */
102
	public function getOwner() {
103
		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
104
			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
105
		}
106
		return parent::getOwner();
107
	}
108
109
	/**
110
	 *
111
	 */
112
	public function delete() {
113
		$this->caldavBackend->deleteSubscription($this->calendarInfo['id']);
0 ignored issues
show
Bug introduced by
The method deleteSubscription() does not exist on Sabre\CalDAV\Backend\BackendInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sabre\CalDAV\Backend\SchedulingSupport or Sabre\CalDAV\Backend\SyncSupport or Sabre\CalDAV\Backend\AbstractBackend or Sabre\CalDAV\Backend\NotificationSupport or Sabre\CalDAV\Backend\SharingSupport or Sabre\CalDAV\Backend\SimplePDO. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
		$this->caldavBackend->/** @scrutinizer ignore-call */ 
114
                        deleteSubscription($this->calendarInfo['id']);
Loading history...
114
	}
115
116
	/**
117
	 * @param PropPatch $propPatch
118
	 */
119
	public function propPatch(PropPatch $propPatch) {
120
		$this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch);
0 ignored issues
show
Bug introduced by
The method updateSubscription() does not exist on Sabre\CalDAV\Backend\BackendInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Sabre\CalDAV\Backend\SchedulingSupport or Sabre\CalDAV\Backend\SyncSupport or Sabre\CalDAV\Backend\AbstractBackend or Sabre\CalDAV\Backend\NotificationSupport or Sabre\CalDAV\Backend\SharingSupport or Sabre\CalDAV\Backend\SimplePDO. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

120
		$this->caldavBackend->/** @scrutinizer ignore-call */ 
121
                        updateSubscription($this->calendarInfo['id'], $propPatch);
Loading history...
121
	}
122
123
	/**
124
	 * @param string $name
125
	 * @return CalendarObject|\Sabre\CalDAV\ICalendarObject
126
	 * @throws NotFound
127
	 */
128
	public function getChild($name) {
129
		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
0 ignored issues
show
Unused Code introduced by
The call to Sabre\CalDAV\Backend\Bac...ce::getCalendarObject() has too many arguments starting with OCA\DAV\CalDAV\CalDavBac...ENDAR_TYPE_SUBSCRIPTION. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
		/** @scrutinizer ignore-call */ 
130
  $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
130
		if (!$obj) {
131
			throw new NotFound('Calendar object not found');
132
		}
133
134
		$obj['acl'] = $this->getChildACL();
135
		return new CachedSubscriptionObject	($this->caldavBackend, $this->calendarInfo, $obj);
136
137
	}
138
139
	/**
140
	 * @return array
141
	 */
142
	public function getChildren():array {
143
		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
0 ignored issues
show
Unused Code introduced by
The call to Sabre\CalDAV\Backend\Bac...e::getCalendarObjects() has too many arguments starting with OCA\DAV\CalDAV\CalDavBac...ENDAR_TYPE_SUBSCRIPTION. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
		/** @scrutinizer ignore-call */ 
144
  $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
144
145
		$children = [];
146
		foreach($objs as $obj) {
147
			$children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
148
		}
149
150
		return $children;
151
	}
152
153
	/**
154
	 * @param array $paths
155
	 * @return array
156
	 */
157
	public function getMultipleChildren(array $paths):array {
158
		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
0 ignored issues
show
Unused Code introduced by
The call to Sabre\CalDAV\Backend\Bac...ltipleCalendarObjects() has too many arguments starting with OCA\DAV\CalDAV\CalDavBac...ENDAR_TYPE_SUBSCRIPTION. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

158
		/** @scrutinizer ignore-call */ 
159
  $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
159
160
		$children = [];
161
		foreach($objs as $obj) {
162
			$children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
163
		}
164
165
		return $children;
166
	}
167
168
	/**
169
	 * @param string $name
170
	 * @param null $calendarData
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $calendarData is correct as it would always require null to be passed?
Loading history...
171
	 * @return null|string|void
172
	 * @throws MethodNotAllowed
173
	 */
174
	public function createFile($name, $calendarData = null) {
175
		throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
176
	}
177
178
	/**
179
	 * @param string $name
180
	 * @return bool
181
	 */
182
	public function childExists($name):bool {
183
		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
0 ignored issues
show
Unused Code introduced by
The call to Sabre\CalDAV\Backend\Bac...ce::getCalendarObject() has too many arguments starting with OCA\DAV\CalDAV\CalDavBac...ENDAR_TYPE_SUBSCRIPTION. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

183
		/** @scrutinizer ignore-call */ 
184
  $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
184
		if (!$obj) {
185
			return false;
186
		}
187
188
		return true;
189
	}
190
191
	/**
192
	 * @param array $filters
193
	 * @return array
194
	 */
195
	public function calendarQuery(array $filters):array {
196
		return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
0 ignored issues
show
Unused Code introduced by
The call to Sabre\CalDAV\Backend\Bac...erface::calendarQuery() has too many arguments starting with OCA\DAV\CalDAV\CalDavBac...ENDAR_TYPE_SUBSCRIPTION. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

196
		return $this->caldavBackend->/** @scrutinizer ignore-call */ calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
197
	}
198
}
199