Completed
Push — master ( 91df00...58343d )
by Phil
10:40
created

Application::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 66
rs 8.7418
c 0
b 0
f 0

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 Björn Schießle <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\FederatedFileSharing\AppInfo;
23
24
use OCA\FederatedFileSharing\AddressHandler;
25
use OCA\FederatedFileSharing\DiscoveryManager;
26
use OCA\FederatedFileSharing\FederatedShareProvider;
27
use OCA\FederatedFileSharing\FedShareManager;
28
use OCA\FederatedFileSharing\Notifications;
29
use OCA\FederatedFileSharing\Controller\RequestHandlerController;
30
use OCA\FederatedFileSharing\TokenHandler;
31
use OCP\AppFramework\App;
32
33
class Application extends App {
34
35
	/** @var FederatedShareProvider */
36
	protected $federatedShareProvider;
37
38
	/**
39
	 * Application constructor.
40
	 */
41
	public function __construct() {
42
		parent::__construct('federatedfilesharing');
43
		$container = $this->getContainer();
44
		$server = $container->getServer();
45
46
		$container->registerService(
47
			'AddressHandler',
48
			function ($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
				return new AddressHandler(
50
					$server->getURLGenerator(),
51
					$server->getL10N('federatedfilesharing')
52
				);
53
			}
54
		);
55
56
		$container->registerService(
57
			'DiscoveryManager',
58
			function ($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
				return new DiscoveryManager(
60
					$server->getMemCacheFactory(),
61
					$server->getHTTPClientService()
62
				);
63
			}
64
		);
65
66
		$container->registerService(
67
			'Notifications',
68
			function ($c) use ($server) {
69
				return new Notifications(
70
					$c->query('AddressHandler'),
71
					$server->getHTTPClientService(),
72
					$c->query('DiscoveryManager'),
73
					$server->getJobList(),
74
					$server->getConfig()
75
				);
76
			}
77
		);
78
79
		$container->registerService(
80
			'FederatedShareManager',
81
			function ($c) use ($server) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
				return new FedShareManager(
83
					$this->getFederatedShareProvider(),
84
					$server->getUserManager(),
85
					$server->getActivityManager(),
86
					$server->getLogger()
87
				);
88
			}
89
		);
90
91
		$container->registerService(
92
			'RequestHandlerController',
93
			function ($c) use ($server) {
94
				return new RequestHandlerController(
95
					$c->query('AppName'),
96
					$c->query('Request'),
97
					$this->getFederatedShareProvider(),
98
					$server->getDatabaseConnection(),
99
					$c->query('Notifications'),
100
					$c->query('AddressHandler'),
101
					$c->query('FederatedShareManager'),
102
					$server->getEventDispatcher()
103
				);
104
			}
105
		);
106
	}
107
108
	/**
109
	 * get instance of federated share provider
110
	 *
111
	 * @return FederatedShareProvider
112
	 */
113
	public function getFederatedShareProvider() {
114
		if ($this->federatedShareProvider === null) {
115
			$this->initFederatedShareProvider();
116
		}
117
		return $this->federatedShareProvider;
118
	}
119
120
	/**
121
	 * initialize federated share provider
122
	 */
123
	protected function initFederatedShareProvider() {
124
		$addressHandler = new AddressHandler(
125
			\OC::$server->getURLGenerator(),
126
			\OC::$server->getL10N('federatedfilesharing')
127
		);
128
		$discoveryManager = new DiscoveryManager(
129
			\OC::$server->getMemCacheFactory(),
130
			\OC::$server->getHTTPClientService()
131
		);
132
		$notifications = new Notifications(
133
			$addressHandler,
134
			\OC::$server->getHTTPClientService(),
135
			$discoveryManager,
136
			\OC::$server->getJobList(),
137
			\OC::$server->getConfig()
138
		);
139
		$tokenHandler = new TokenHandler(
140
			\OC::$server->getSecureRandom()
141
		);
142
143
		$this->federatedShareProvider = new FederatedShareProvider(
144
			\OC::$server->getDatabaseConnection(),
145
			$addressHandler,
146
			$notifications,
147
			$tokenHandler,
148
			\OC::$server->getL10N('federatedfilesharing'),
149
			\OC::$server->getLogger(),
150
			\OC::$server->getLazyRootFolder(),
151
			\OC::$server->getConfig(),
152
			\OC::$server->getUserManager()
153
		);
154
	}
155
}
156