Passed
Pull Request — master (#878)
by Björn
07:12
created

Application::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 78

Duplication

Lines 16
Ratio 20.51 %

Importance

Changes 0
Metric Value
dl 16
loc 78
rs 8.48
c 0
b 0
f 0
cc 1
nc 1
nop 1

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
 * 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\CloudFederationProviderCalendar;
25
use OCA\Calendar\Controller;
26
27
use OCP\AppFramework\App;
28
use OCP\AppFramework\IAppContainer;
29
30
class Application extends App {
31
32
	/**
33
	 * @param array $params
34
	 */
35
	public function __construct($params=[]) {
36
		parent::__construct('calendar', $params);
37
		$container = $this->getContainer();
38
39
		$container->registerService('ContactController', function(IAppContainer $c) {
40
			$request = $c->query('Request');
41
			$contacts = $c->getServer()->getContactsManager();
42
43
			return new Controller\ContactController($c->getAppName(), $request, $contacts);
44
		});
45
46
		$container->registerService('EmailController', function(IAppContainer $c) {
47
			$request = $c->query('Request');
48
			$userSession = $c->getServer()->getUserSession();
49
			$config = $c->getServer()->getConfig();
50
			$mailer = $c->getServer()->getMailer();
51
			$l10n = $c->getServer()->getL10N($c->query('AppName'));
52
			$defaults = new \OCP\Defaults();
53
54
			return new Controller\EmailController($c->getAppName(), $request, $userSession, $config, $mailer, $l10n, $defaults);
55
		});
56
57
		$container->registerService('FederationController', function(IAppContainer $c) {
58
			$request = $c->query('Request');
59
			$server = $c->getServer();
60
61
			return new Controller\FederationController(
62
				$c->getAppName(),
63
				$request,
64
				$server->getCloudIdManager(),
65
				$server->getCloudFederationProviderManager(),
66
				$server->getCloudFederationFactory(),
67
				$server->getSecureRandom(),
68
				$server->getUserSession()
69
			);
70
		});
71
72
73 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...
74
			$request = $c->query('Request');
75
			$client = $c->getServer()->getHTTPClientService();
76
			$l10n = $c->getServer()->getL10N($c->query('AppName'));
77
			$logger = $c->getServer()->getLogger();
78
79
			return new Controller\ProxyController($c->getAppName(), $request, $client, $l10n, $logger);
80
		});
81
82
		$container->registerService('SettingsController', function(IAppContainer $c) {
83
			$request = $c->query('Request');
84
			$config = $c->getServer()->getConfig();
85
			$userSession = $c->getServer()->getUserSession();
86
87
			return new Controller\SettingsController($c->getAppName(), $request, $userSession, $config);
88
		});
89
90
		$container->registerService('TimezoneController', function(IAppContainer $c) {
91
			$request = $c->query('Request');
92
93
			return new Controller\TimezoneController($c->getAppName(), $request);
94
		});
95
96 View Code Duplication
		$container->registerService('ViewController', 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...
97
			$request = $c->query('Request');
98
			$userSession = $c->getServer()->getUserSession();
99
			$config = $c->getServer()->getConfig();
100
			$urlGenerator = $c->getServer()->getURLGenerator();
101
102
			return new Controller\ViewController($c->getAppName(), $request, $userSession, $config, $urlGenerator);
103
		});
104
105
		$cloudFederationManager = $container->getServer()->getCloudFederationProviderManager();
106
		$cloudFederationManager->addCloudFederationProvider('calendar',
107
			'Federated calendar Sharing',
108
			function() {
109
				return new CloudFederationProviderCalendar();
110
			});
111
112
	}
113
114
	/**
115
	 * register navigation entry
116
	 */
117
	public function registerNavigation() {
118
		$appName = $this->getContainer()->getAppName();
119
		$server = $this->getContainer()->getServer();
120
121
		$server->getNavigationManager()->add(function() use ($appName, $server) {
122
			return [
123
				'id' => $appName,
124
				'order' => 5,
125
				'href' => $server->getURLGenerator()
126
					->linkToRoute('calendar.view.index'),
127
				'icon' => $server->getURLGenerator()
128
					->imagePath($appName, 'calendar.svg'),
129
				'name' => $server->getL10N($appName)->t('Calendar'),
130
			];
131
		});
132
	}
133
}
134