Completed
Push — master ( 74bd2c...830834 )
by Thomas
09:42
created

RootCollection::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 79
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 63
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 79
rs 8.8701

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * @author Arthur Schiwon <[email protected]>
4
 * @author Joas Schilling <[email protected]>
5
 * @author Thomas Müller <[email protected]>
6
 * @author Vincent Petry <[email protected]>
7
 *
8
 * @copyright Copyright (c) 2016, ownCloud GmbH.
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;
25
26
use OCA\DAV\CalDAV\CalDavBackend;
27
use OCA\DAV\CalDAV\CalendarRoot;
28
use OCA\DAV\CalDAV\PublicCalendarRoot;
29
use OCA\DAV\CardDAV\AddressBookRoot;
30
use OCA\DAV\CardDAV\CardDavBackend;
31
use OCA\DAV\Connector\Sabre\Principal;
32
use OCA\DAV\DAV\GroupPrincipalBackend;
33
use OCA\DAV\DAV\SystemPrincipalBackend;
34
use Sabre\CalDAV\Principal\Collection;
35
use Sabre\DAV\SimpleCollection;
36
37
class RootCollection extends SimpleCollection {
38
39
	public function __construct() {
40
		$config = \OC::$server->getConfig();
41
		$db = \OC::$server->getDatabaseConnection();
42
		$dispatcher = \OC::$server->getEventDispatcher();
43
		$userPrincipalBackend = new Principal(
44
			\OC::$server->getUserManager(),
45
			\OC::$server->getGroupManager()
46
		);
47
		$groupPrincipalBackend = new GroupPrincipalBackend(
48
			\OC::$server->getGroupManager()
49
		);
50
		// as soon as debug mode is enabled we allow listing of principals
51
		$disableListing = !$config->getSystemValue('debug', false);
52
53
		// setup the first level of the dav tree
54
		$userPrincipals = new Collection($userPrincipalBackend, 'principals/users');
55
		$userPrincipals->disableListing = $disableListing;
56
		$groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups');
57
		$groupPrincipals->disableListing = $disableListing;
58
		$systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system');
59
		$systemPrincipals->disableListing = $disableListing;
60
		$filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users');
61
		$filesCollection->disableListing = $disableListing;
62
		$caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $config);
63
		$calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users');
64
		$calendarRoot->disableListing = $disableListing;
65
		$publicCalendarRoot = new PublicCalendarRoot($caldavBackend);
66
		$publicCalendarRoot->disableListing = $disableListing;
67
68
		$systemTagCollection = new SystemTag\SystemTagsByIdCollection(
69
			\OC::$server->getSystemTagManager(),
70
			\OC::$server->getUserSession(),
71
			\OC::$server->getGroupManager()
72
		);
73
		$systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection(
74
			\OC::$server->getSystemTagManager(),
75
			\OC::$server->getSystemTagObjectMapper(),
76
			\OC::$server->getUserSession(),
77
			\OC::$server->getGroupManager(),
78
			\OC::$server->getRootFolder()
79
		);
80
		$commentsCollection = new Comments\RootCollection(
81
			\OC::$server->getCommentsManager(),
82
			\OC::$server->getUserManager(),
83
			\OC::$server->getUserSession(),
84
			\OC::$server->getEventDispatcher(),
85
			\OC::$server->getLogger()
86
		);
87
88
		$usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher);
89
		$usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users');
90
		$usersAddressBookRoot->disableListing = $disableListing;
91
92
		$systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, $dispatcher);
93
		$systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system');
94
		$systemAddressBookRoot->disableListing = $disableListing;
95
96
		$uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users');
97
		$uploadCollection->disableListing = $disableListing;
98
99
		$children = [
100
				new SimpleCollection('principals', [
101
						$userPrincipals,
102
						$groupPrincipals,
103
						$systemPrincipals]),
104
				$filesCollection,
105
				$calendarRoot,
106
				$publicCalendarRoot,
107
				new SimpleCollection('addressbooks', [
108
						$usersAddressBookRoot,
109
						$systemAddressBookRoot]),
110
				$systemTagCollection,
111
				$systemTagRelationsCollection,
112
				$commentsCollection,
113
				$uploadCollection,
114
		];
115
116
		parent::__construct('root', $children);
117
	}
118
119
}
120