Completed
Push — master ( ba9b17...94004c )
by Lukas
05:19 queued 04:59
created

Application::__construct()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 182
Code Lines 134

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 134
nc 1
nop 1
dl 0
loc 182
rs 8.2857
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
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Georg Ehrke <[email protected]>
8
 * @author Joas Schilling <[email protected]>
9
 * @author Lukas Reschke <[email protected]>
10
 * @author Morris Jobke <[email protected]>
11
 * @author Robin Appelman <[email protected]>
12
 * @author Roeland Jago Douma <[email protected]>
13
 * @author Thomas Müller <[email protected]>
14
 *
15
 * @license AGPL-3.0
16
 *
17
 * This code is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License, version 3,
19
 * as published by the Free Software Foundation.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License, version 3,
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
28
 *
29
 */
30
31
namespace OC\Settings;
32
33
use OC\App\AppStore\Fetcher\AppFetcher;
34
use OC\App\AppStore\Fetcher\CategoryFetcher;
35
use OC\AppFramework\Utility\TimeFactory;
36
use OC\Authentication\Token\IProvider;
37
use OC\Files\View;
38
use OC\Server;
39
use OC\Settings\Controller\AppSettingsController;
40
use OC\Settings\Controller\AuthSettingsController;
41
use OC\Settings\Controller\CertificateController;
42
use OC\Settings\Controller\CheckSetupController;
43
use OC\Settings\Controller\EncryptionController;
44
use OC\Settings\Controller\GroupsController;
45
use OC\Settings\Controller\LogSettingsController;
46
use OC\Settings\Controller\MailSettingsController;
47
use OC\Settings\Controller\SecuritySettingsController;
48
use OC\Settings\Controller\UsersController;
49
use OC\Settings\Middleware\SubadminMiddleware;
50
use OCP\AppFramework\App;
51
use OCP\AppFramework\IAppContainer;
52
use OCP\IContainer;
53
use OCP\Settings\IManager;
54
use OCP\Util;
55
56
/**
57
 * @package OC\Settings
58
 */
59
class Application extends App {
60
61
62
	/**
63
	 * @param array $urlParams
64
	 */
65
	public function __construct(array $urlParams=[]){
66
		parent::__construct('settings', $urlParams);
67
68
		$container = $this->getContainer();
69
70
		// Register Middleware
71
		$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
72
		/**
73
		 * Controllers
74
		 */
75
		$container->registerService('MailSettingsController', function(IContainer $c) {
76
			return new MailSettingsController(
77
				$c->query('AppName'),
78
				$c->query('Request'),
79
				$c->query('L10N'),
80
				$c->query('Config'),
81
				$c->query('UserSession'),
82
				$c->query('Defaults'),
83
				$c->query('Mailer'),
84
				$c->query('DefaultMailAddress')
85
			);
86
		});
87
		$container->registerService('EncryptionController', function(IContainer $c) {
88
			return new EncryptionController(
89
				$c->query('AppName'),
90
				$c->query('Request'),
91
				$c->query('L10N'),
92
				$c->query('Config'),
93
				$c->query('DatabaseConnection'),
94
				$c->query('UserManager'),
95
				new View(),
96
				$c->query('Logger')
97
			);
98
		});
99
100
		$container->registerService('AppSettingsController', function(IContainer $c) {
101
			return new AppSettingsController(
102
				$c->query('AppName'),
103
				$c->query('Request'),
104
				$c->query('L10N'),
105
				$c->query('Config'),
106
				$c->query('INavigationManager'),
107
				$c->query('IAppManager'),
108
				$c->query('CategoryFetcher'),
109
				$c->query('AppFetcher'),
110
				\OC::$server->getL10NFactory()
111
			);
112
		});
113
		$container->registerService('AuthSettingsController', function(IContainer $c) {
114
			return new AuthSettingsController(
115
				$c->query('AppName'),
116
				$c->query('Request'),
117
				$c->query('ServerContainer')->query('OC\Authentication\Token\IProvider'),
118
				$c->query('UserManager'),
119
				$c->query('ServerContainer')->getSession(),
120
				$c->query('ServerContainer')->getSecureRandom(),
121
				$c->query('UserId')
122
			);
123
		});
124
		$container->registerService('SecuritySettingsController', function(IContainer $c) {
125
			return new SecuritySettingsController(
126
				$c->query('AppName'),
127
				$c->query('Request'),
128
				$c->query('Config')
129
			);
130
		});
131
		$container->registerService('AccountManager', function(IAppContainer $c) {
132
			return new AccountManager($c->getServer()->getDatabaseConnection());
133
		});
134
		$container->registerService('CertificateController', function(IContainer $c) {
135
			return new CertificateController(
136
				$c->query('AppName'),
137
				$c->query('Request'),
138
				$c->query('CertificateManager'),
139
				$c->query('SystemCertificateManager'),
140
				$c->query('L10N'),
141
				$c->query('IAppManager')
142
			);
143
		});
144
		$container->registerService('GroupsController', function(IContainer $c) {
145
			return new GroupsController(
146
				$c->query('AppName'),
147
				$c->query('Request'),
148
				$c->query('GroupManager'),
149
				$c->query('UserSession'),
150
				$c->query('IsAdmin'),
151
				$c->query('L10N')
152
			);
153
		});
154
		$container->registerService('UsersController', function(IContainer $c) {
155
			return new UsersController(
156
				$c->query('AppName'),
157
				$c->query('Request'),
158
				$c->query('UserManager'),
159
				$c->query('GroupManager'),
160
				$c->query('UserSession'),
161
				$c->query('Config'),
162
				$c->query('IsAdmin'),
163
				$c->query('L10N'),
164
				$c->query('Logger'),
165
				$c->query('Defaults'),
166
				$c->query('Mailer'),
167
				$c->query('DefaultMailAddress'),
168
				$c->query('URLGenerator'),
169
				$c->query('OCP\\App\\IAppManager'),
170
				$c->query('OCP\\IAvatarManager'),
171
				$c->query('AccountManager')
172
			);
173
		});
174
		$container->registerService('LogSettingsController', function(IContainer $c) {
175
			return new LogSettingsController(
176
				$c->query('AppName'),
177
				$c->query('Request'),
178
				$c->query('Config'),
179
				$c->query('L10N')
180
			);
181
		});
182
		$container->registerService('CheckSetupController', function(IContainer $c) {
183
			return new CheckSetupController(
0 ignored issues
show
Bug introduced by
The call to CheckSetupController::__construct() misses a required argument $logger.

This check looks for function calls that miss required arguments.

Loading history...
184
				$c->query('AppName'),
185
				$c->query('Request'),
186
				$c->query('Config'),
187
				$c->query('ClientService'),
188
				$c->query('URLGenerator'),
189
				$c->query('Util'),
190
				$c->query('L10N'),
191
				$c->query('Checker')
192
			);
193
		});
194
195
196
		/**
197
		 * Core class wrappers
198
		 */
199
		/** FIXME: Remove once OC_User is non-static and mockable */
200
		$container->registerService('isAdmin', function() {
201
			return \OC_User::isAdminUser(\OC_User::getUser());
202
		});
203
		/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
204
		$container->registerService('isSubAdmin', function(IContainer $c) {
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...
205
			$userObject = \OC::$server->getUserSession()->getUser();
206
			$isSubAdmin = false;
207
			if($userObject !== null) {
208
				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
209
			}
210
			return $isSubAdmin;
211
		});
212
		$container->registerService('fromMailAddress', function() {
213
			return Util::getDefaultEmailAddress('no-reply');
214
		});
215
		$container->registerService('userCertificateManager', function(IContainer $c) {
216
			return $c->query('ServerContainer')->getCertificateManager();
217
		}, false);
218
		$container->registerService('systemCertificateManager', function (IContainer $c) {
219
			return $c->query('ServerContainer')->getCertificateManager(null);
220
		}, false);
221
		$container->registerService(IProvider::class, function (IContainer $c) {
222
			return $c->query('ServerContainer')->query(IProvider::class);
223
		});
224
		$container->registerService(IManager::class, function (IContainer $c) {
225
			return $c->query('ServerContainer')->getSettingsManager();
226
		});
227
		$container->registerService(AppFetcher::class, function (IContainer $c) {
228
			/** @var Server $server */
229
			$server = $c->query('ServerContainer');
230
			return new AppFetcher(
231
				$server->getAppDataDir('appstore'),
232
				$server->getHTTPClientService(),
233
				$server->query(TimeFactory::class),
234
				$server->getConfig()
235
			);
236
		});
237
		$container->registerService(CategoryFetcher::class, function (IContainer $c) {
238
			/** @var Server $server */
239
			$server = $c->query('ServerContainer');
240
			return new CategoryFetcher(
241
				$server->getAppDataDir('appstore'),
242
				$server->getHTTPClientService(),
243
				$server->query(TimeFactory::class)
244
			);
245
		});
246
	}
247
}
248