Completed
Push — master ( 4c6036...8838ed )
by Morris
11:46
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 39.39 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 13
loc 33
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 13 31 3

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
namespace OCA\Provisioning_API\AppInfo;
4
5
use OC\AppFramework\Utility\SimpleContainer;
6
use OC\AppFramework\Utility\TimeFactory;
7
use OC\Settings\Mailer\NewUserMailHelper;
8
use OCA\Provisioning_API\Middleware\ProvisioningApiMiddleware;
9
use OCP\AppFramework\App;
10
use OCP\Util;
11
12
class Application extends App {
13
	public function __construct(array $urlParams = array()) {
14
		parent::__construct('provisioning_api', $urlParams);
15
16
		$container = $this->getContainer();
17
		$server = $container->getServer();
18
19 View Code Duplication
		$container->registerService(NewUserMailHelper::class, function(SimpleContainer $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...
20
			return new NewUserMailHelper(
21
				$server->getThemingDefaults(),
22
				$server->getURLGenerator(),
23
				$server->getL10N('settings'),
24
				$server->getMailer(),
25
				$server->getSecureRandom(),
26
				new TimeFactory(),
27
				$server->getConfig(),
28
				$server->getCrypto(),
29
				Util::getDefaultEmailAddress('no-reply')
30
			);
31
		});
32
		$container->registerService('ProvisioningApiMiddleware', function(SimpleContainer $c) use ($server) {
33
			$user = $server->getUserManager()->get($c['UserId']);
34
			$isAdmin = $user !== null ? $server->getGroupManager()->isAdmin($user->getUID()) : false;
35
			$isSubAdmin = $user !== null ? $server->getGroupManager()->getSubAdmin()->isSubAdmin($user) : false;
36
			return new ProvisioningApiMiddleware(
37
				$c['ControllerMethodReflector'],
38
				$isAdmin,
39
				$isSubAdmin
40
			);
41
		});
42
		$container->registerMiddleWare('ProvisioningApiMiddleware');
43
	}
44
}
45