Completed
Push — master ( f692ea...2eca9c )
by Lukas
08:20
created

Application::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 60
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 38
nc 1
nop 1
dl 0
loc 60
rs 9.5555
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\Server;
38
use OC\Settings\Middleware\SubadminMiddleware;
39
use OCP\AppFramework\App;
40
use OCP\IContainer;
41
use OCP\Settings\IManager;
42
use OCP\Util;
43
44
/**
45
 * @package OC\Settings
46
 */
47
class Application extends App {
48
49
50
	/**
51
	 * @param array $urlParams
52
	 */
53
	public function __construct(array $urlParams=[]){
54
		parent::__construct('settings', $urlParams);
55
56
		$container = $this->getContainer();
57
58
		// Register Middleware
59
		$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
60
		$container->registerMiddleWare('SubadminMiddleware');
61
62
		/**
63
		 * Core class wrappers
64
		 */
65
		/** FIXME: Remove once OC_User is non-static and mockable */
66
		$container->registerService('isAdmin', function() {
67
			return \OC_User::isAdminUser(\OC_User::getUser());
68
		});
69
		/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
70
		$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...
71
			$userObject = \OC::$server->getUserSession()->getUser();
72
			$isSubAdmin = false;
73
			if($userObject !== null) {
74
				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
75
			}
76
			return $isSubAdmin;
77
		});
78
		$container->registerService('fromMailAddress', function() {
79
			return Util::getDefaultEmailAddress('no-reply');
80
		});
81
		$container->registerService('userCertificateManager', function(IContainer $c) {
82
			return $c->query('ServerContainer')->getCertificateManager();
83
		}, false);
84
		$container->registerService('systemCertificateManager', function (IContainer $c) {
85
			return $c->query('ServerContainer')->getCertificateManager(null);
86
		}, false);
87
		$container->registerService(IProvider::class, function (IContainer $c) {
88
			return $c->query('ServerContainer')->query(IProvider::class);
89
		});
90
		$container->registerService(IManager::class, function (IContainer $c) {
91
			return $c->query('ServerContainer')->getSettingsManager();
92
		});
93
		$container->registerService(AppFetcher::class, function (IContainer $c) {
94
			/** @var Server $server */
95
			$server = $c->query('ServerContainer');
96
			return new AppFetcher(
97
				$server->getAppDataDir('appstore'),
98
				$server->getHTTPClientService(),
99
				$server->query(TimeFactory::class),
100
				$server->getConfig()
101
			);
102
		});
103
		$container->registerService(CategoryFetcher::class, function (IContainer $c) {
104
			/** @var Server $server */
105
			$server = $c->query('ServerContainer');
106
			return new CategoryFetcher(
107
				$server->getAppDataDir('appstore'),
108
				$server->getHTTPClientService(),
109
				$server->query(TimeFactory::class)
110
			);
111
		});
112
	}
113
}
114