Completed
Push — master ( 5ca5eb...afb5d4 )
by Lukas
16:52
created

Application   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 84
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 0
Dependencies 14

Importance

Changes 0
Metric Value
dl 20
loc 84
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 14

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 20 77 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Mailer\NewUserMailHelper;
39
use OC\Settings\Middleware\SubadminMiddleware;
40
use OCP\AppFramework\App;
41
use OCP\Defaults;
42
use OCP\IContainer;
43
use OCP\Settings\IManager;
44
use OCP\Util;
45
46
/**
47
 * @package OC\Settings
48
 */
49
class Application extends App {
50
51
52
	/**
53
	 * @param array $urlParams
54
	 */
55
	public function __construct(array $urlParams=[]){
56
		parent::__construct('settings', $urlParams);
57
58
		$container = $this->getContainer();
59
60
		// Register Middleware
61
		$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class);
62
		$container->registerMiddleWare('SubadminMiddleware');
63
64
		/**
65
		 * Core class wrappers
66
		 */
67
		/** FIXME: Remove once OC_User is non-static and mockable */
68
		$container->registerService('isAdmin', function() {
69
			return \OC_User::isAdminUser(\OC_User::getUser());
70
		});
71
		/** FIXME: Remove once OC_SubAdmin is non-static and mockable */
72
		$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...
73
			$userObject = \OC::$server->getUserSession()->getUser();
74
			$isSubAdmin = false;
75
			if($userObject !== null) {
76
				$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
77
			}
78
			return $isSubAdmin;
79
		});
80
		$container->registerService('userCertificateManager', function(IContainer $c) {
81
			return $c->query('ServerContainer')->getCertificateManager();
82
		}, false);
83
		$container->registerService('systemCertificateManager', function (IContainer $c) {
84
			return $c->query('ServerContainer')->getCertificateManager(null);
85
		}, false);
86
		$container->registerService(IProvider::class, function (IContainer $c) {
87
			return $c->query('ServerContainer')->query(IProvider::class);
88
		});
89
		$container->registerService(IManager::class, function (IContainer $c) {
90
			return $c->query('ServerContainer')->getSettingsManager();
91
		});
92
93
		$container->registerService(NewUserMailHelper::class, function (IContainer $c) {
94
			/** @var Server $server */
95
			$server = $c->query('ServerContainer');
96
			/** @var Defaults $defaults */
97
			$defaults = $server->query(Defaults::class);
98
99
			return new NewUserMailHelper(
100
				$defaults,
101
				$server->getURLGenerator(),
102
				$server->getL10N('settings'),
103
				$server->getMailer(),
104
				$server->getSecureRandom(),
105
				new TimeFactory(),
106
				$server->getConfig(),
107
				$server->getCrypto(),
108
				Util::getDefaultEmailAddress('no-reply')
109
			);
110
		});
111 View Code Duplication
		$container->registerService(AppFetcher::class, function (IContainer $c) {
112
			/** @var Server $server */
113
			$server = $c->query('ServerContainer');
114
			return new AppFetcher(
115
				$server->getAppDataDir('appstore'),
116
				$server->getHTTPClientService(),
117
				$server->query(TimeFactory::class),
118
				$server->getConfig()
119
			);
120
		});
121 View Code Duplication
		$container->registerService(CategoryFetcher::class, function (IContainer $c) {
122
			/** @var Server $server */
123
			$server = $c->query('ServerContainer');
124
			return new CategoryFetcher(
125
				$server->getAppDataDir('appstore'),
126
				$server->getHTTPClientService(),
127
				$server->query(TimeFactory::class),
128
				$server->getConfig()
129
			);
130
		});
131
	}
132
}
133