Completed
Push — master ( 7481a4...1f1f17 )
by Georg
23s queued 11s
created

Application   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 81
Duplicated Lines 23.46 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 19
loc 81
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerNavigation() 0 16 1
B __construct() 19 55 1

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
 * Calendar App
4
 *
5
 * @author Georg Ehrke
6
 * @copyright 2017 Georg Ehrke <[email protected]>
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
10
 * License as published by the Free Software Foundation; either
11
 * version 3 of the License, or any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public
19
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
namespace OCA\Calendar\AppInfo;
23
24
use OCA\Calendar\Controller;
25
26
use OCP\AppFramework\App;
27
use OCP\AppFramework\IAppContainer;
28
29
class Application extends App {
30
31
	/**
32
	 * @param array $params
33
	 */
34
	public function __construct($params=[]) {
35
		parent::__construct('calendar', $params);
36
		$container = $this->getContainer();
37
38
		$container->registerService('ContactController', function(IAppContainer $c) {
39
			$request = $c->query('Request');
40
			$contacts = $c->getServer()->getContactsManager();
41
42
			return new Controller\ContactController($c->getAppName(), $request, $contacts);
43
		});
44
45 View Code Duplication
		$container->registerService('EmailController', function(IAppContainer $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
			$request = $c->query('Request');
47
			$userSession = $c->getServer()->getUserSession();
48
			$config = $c->getServer()->getConfig();
49
			$mailer = $c->getServer()->getMailer();
50
			$l10n = $c->getServer()->getL10N($c->query('AppName'));
51
			$defaults = new \OCP\Defaults();
52
53
			return new Controller\EmailController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults);
54
		});
55
56 View Code Duplication
		$container->registerService('ProxyController', function(IAppContainer $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
			$request = $c->query('Request');
58
			$client = $c->getServer()->getHTTPClientService();
59
			$l10n = $c->getServer()->getL10N($c->query('AppName'));
60
			$logger = $c->getServer()->getLogger();
61
			$config = $c->getServer()->getConfig();
62
63
			return new Controller\ProxyController($c->getAppName(), $request, $client, $l10n, $logger, $config);
64
		});
65
66
		$container->registerService('SettingsController', function(IAppContainer $c) {
67
			$request = $c->query('Request');
68
			$config = $c->getServer()->getConfig();
69
			$userSession = $c->getServer()->getUserSession();
70
71
			return new Controller\SettingsController($c->getAppName(), $request, $userSession, $config);
72
		});
73
74
		$container->registerService('TimezoneController', function(IAppContainer $c) {
75
			$request = $c->query('Request');
76
77
			return new Controller\TimezoneController($c->getAppName(), $request);
78
		});
79
80
		$container->registerService('ViewController', function(IAppContainer $c) {
81
			$request = $c->query('Request');
82
			$userSession = $c->getServer()->getUserSession();
83
			$config = $c->getServer()->getConfig();
84
			$urlGenerator = $c->getServer()->getURLGenerator();
85
86
			return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $urlGenerator);
87
		});
88
	}
89
90
	/**
91
	 * register navigation entry
92
	 */
93
	public function registerNavigation() {
94
		$appName = $this->getContainer()->getAppName();
95
		$server = $this->getContainer()->getServer();
96
97
		$server->getNavigationManager()->add(function() use ($appName, $server) {
98
			return [
99
				'id' => $appName,
100
				'order' => 5,
101
				'href' => $server->getURLGenerator()
102
					->linkToRoute('calendar.view.index'),
103
				'icon' => $server->getURLGenerator()
104
					->imagePath($appName, 'calendar.svg'),
105
				'name' => $server->getL10N($appName)->t('Calendar'),
106
			];
107
		});
108
	}
109
}
110