Completed
Push — master ( aedd1f...4456fa )
by Lukas
06:45
created

CalendarHome::getCalDAVBackend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Lukas Reschke <[email protected]>
6
 * @author Thomas Müller <[email protected]>
7
 *
8
 * @license AGPL-3.0
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
namespace OCA\DAV\CalDAV;
24
25
use Sabre\CalDAV\Backend\BackendInterface;
26
use Sabre\CalDAV\Backend\NotificationSupport;
27
use Sabre\CalDAV\Backend\SchedulingSupport;
28
use Sabre\CalDAV\Backend\SubscriptionSupport;
29
use Sabre\CalDAV\Schedule\Inbox;
30
use Sabre\CalDAV\Schedule\Outbox;
31
use Sabre\CalDAV\Subscriptions\Subscription;
32
use Sabre\DAV\Exception\NotFound;
33
34
class CalendarHome extends \Sabre\CalDAV\CalendarHome {
35
36
	/** @var \OCP\IL10N */
37
	private $l10n;
38
39
	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
40
		parent::__construct($caldavBackend, $principalInfo);
41
		$this->l10n = \OC::$server->getL10N('dav');
42
	}
43
44
	/**
45
	 * @return BackendInterface
46
	 */
47
	public function getCalDAVBackend() {
48
		return $this->caldavBackend;
49
	}
50
51
	/**
52
	 * @inheritdoc
53
	 */
54
	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...
55
		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
56
		$objects = [];
57
		foreach ($calendars as $calendar) {
58
			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
59
		}
60
61
		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...
62
			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
63
			$objects[] = new Outbox($this->principalInfo['uri']);
64
		}
65
66
		// We're adding a notifications node, if it's supported by the backend.
67 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...
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...
68
			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
69
		}
70
71
		// If the backend supports subscriptions, we'll add those as well,
72 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...
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...
73
			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
74
				$objects[] = new Subscription($this->caldavBackend, $subscription);
75
			}
76
		}
77
78
		return $objects;
79
	}
80
81
	/**
82
	 * @inheritdoc
83
	 */
84
	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...
85
		// Special nodes
86
		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...
87
			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
88
		}
89
		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...
90
			return new Outbox($this->principalInfo['uri']);
91
		}
92 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...
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...
93
			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
94
		}
95
96
		// Calendars
97
		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
98
			if ($calendar['uri'] === $name) {
99
				return new Calendar($this->caldavBackend, $calendar, $this->l10n);
100
			}
101
		}
102
103 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...
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...
104
			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
105
				if ($subscription['uri'] === $name) {
106
					return new Subscription($this->caldavBackend, $subscription);
107
				}
108
			}
109
110
		}
111
112
		throw new NotFound('Node with name \'' . $name . '\' could not be found');
113
	}
114
}
115