Completed
Pull Request — stable9 (#58)
by Joas
02:24
created

Application::__construct()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 217
Code Lines 135

Duplication

Lines 50
Ratio 23.04 %

Code Coverage

Tests 119
CRAP Score 3

Importance

Changes 0
Metric Value
dl 50
loc 217
ccs 119
cts 119
cp 1
rs 8.2857
c 0
b 0
f 0
cc 3
eloc 135
nc 1
nop 1
crap 3

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 Joas Schilling <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program 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 License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Activity\AppInfo;
24
25
use OC\Files\View;
26
use OCA\Activity\Consumer;
27
use OCA\Activity\Controller\Activities;
28
use OCA\Activity\Controller\EndPoint;
29
use OCA\Activity\Controller\Feed;
30
use OCA\Activity\Controller\OCSEndPoint;
31
use OCA\Activity\Controller\Settings;
32
use OCA\Activity\Data;
33
use OCA\Activity\DataHelper;
34
use OCA\Activity\GroupHelper;
35
use OCA\Activity\FilesHooks;
36
use OCA\Activity\MailQueueHandler;
37
use OCA\Activity\Navigation;
38
use OCA\Activity\Parameter\Factory;
39
use OCA\Activity\UserSettings;
40
use OCA\Activity\ViewInfoCache;
41
use OCP\AppFramework\App;
42
use OCP\IContainer;
43
44
class Application extends App {
45 26
	public function __construct (array $urlParams = array()) {
46 26
		parent::__construct('activity', $urlParams);
47 26
		$container = $this->getContainer();
48
49
		/**
50
		 * Activity Services
51
		 */
52
		$container->registerService('ActivityData', function(IContainer $c) {
53
			/** @var \OC\Server $server */
54 18
			$server = $c->query('ServerContainer');
55 18
			return new Data(
56 18
				$server->getActivityManager(),
57 18
				$server->getDatabaseConnection(),
58 18
				$server->getUserSession()
59
			);
60 26
		});
61
62
		$container->registerService('ActivityL10N', function(IContainer $c) {
63 16
			return $c->query('ServerContainer')->getL10N('activity');
64 26
		});
65
66
67
		$container->registerService('Consumer', function(IContainer $c) {
68 2
			return new Consumer(
69 2
				$c->query('ActivityData'),
70 2
				$c->query('UserSettings')
71
			);
72 26
		});
73
74
		$container->registerService('DataHelper', function(IContainer $c) {
75
			/** @var \OC\Server $server */
76 10
			$server = $c->query('ServerContainer');
77 10
			return new DataHelper(
78 10
				$server->getActivityManager(),
79 10
				new Factory(
80 10
					$server->getActivityManager(),
81 10
					$server->getUserManager(),
82 10
					$server->getURLGenerator(),
83 10
					$server->getContactsManager(),
84 10
					$c->query('OCA\Activity\ViewInfoCache'),
85 10
					$c->query('ActivityL10N'),
86 10
					$c->query('CurrentUID')
87
				),
88 10
				$server->getL10NFactory(),
89 10
				$c->query('ActivityL10N')
90
			);
91 26
		});
92
93
		$container->registerService('GroupHelper', function(IContainer $c) {
94 6
			return new GroupHelper(
95 6
				$c->query('ServerContainer')->getActivityManager(),
96 6
				$c->query('DataHelper'),
97 6
				true
98
			);
99 26
		});
100
101
		$container->registerService('GroupHelperSingleEntries', function(IContainer $c) {
102 1
			return new GroupHelper(
103 1
				$c->query('ServerContainer')->getActivityManager(),
104 1
				$c->query('DataHelper'),
105 1
				false
106
			);
107 26
		});
108
109
		$container->registerService('Hooks', function(IContainer $c) {
110
			/** @var \OC\Server $server */
111 1
			$server = $c->query('ServerContainer');
112
113 1
			return new FilesHooks(
114 1
				$server->getActivityManager(),
115 1
				$c->query('ActivityData'),
116 1
				$c->query('UserSettings'),
117 1
				$server->getGroupManager(),
118 1
				new View(''),
119 1
				$server->getDatabaseConnection(),
120 1
				$server->getURLGenerator(),
121 1
				$c->query('CurrentUID')
122
			);
123 26
		});
124
125
		$container->registerService('MailQueueHandler', function(IContainer $c) {
126
			/** @var \OC\Server $server */
127 2
			$server = $c->query('ServerContainer');
128
129 2
			return new MailQueueHandler(
130 2
				$server->getDateTimeFormatter(),
131 2
				$server->getDatabaseConnection(),
132 2
				$c->query('DataHelper'),
133 2
				$server->getMailer(),
134 2
				$server->getURLGenerator(),
135 2
				$server->getUserManager(),
136 2
				$server->getActivityManager()
137
			);
138 26
		});
139
140
		$container->registerService('Navigation', function(IContainer $c) {
141
			/** @var \OC\Server $server */
142 2
			$server = $c->query('ServerContainer');
143 2
			$rssToken = ($c->query('CurrentUID') !== '') ? $server->getConfig()->getUserValue($c->query('CurrentUID'), 'activity', 'rsstoken') : '';
144
145 2
			return new Navigation(
146 2
				$c->query('ActivityL10N'),
147 2
				$server->getActivityManager(),
148 2
				$server->getURLGenerator(),
149 2
				$c->query('UserSettings'),
150 2
				$c->query('CurrentUID'),
151
				$rssToken
152
			);
153 26
		});
154
155
		$container->registerService('UserSettings', function(IContainer $c) {
156
			/** @var \OC\Server $server */
157 14
			$server = $c->query('ServerContainer');
158 14
			return new UserSettings(
159 14
				$server->getActivityManager(),
160 14
				$server->getConfig(),
161 14
				$c->query('ActivityData')
162
			);
163 26
		});
164
165
		$container->registerService('OCA\Activity\ViewInfoCache', function() {
166 11
			return new ViewInfoCache(
167 11
				new View('')
168
			);
169 26
		});
170
171
		/**
172
		 * Core Services
173
		 */
174
		$container->registerService('CurrentUID', function(IContainer $c) {
175
			/** @var \OC\Server $server */
176 15
			$server = $c->query('ServerContainer');
177
178 15
			$user = $server->getUserSession()->getUser();
179 15
			return ($user) ? $user->getUID() : '';
180 26
		});
181
182
		/**
183
		 * Controller
184
		 */
185 View Code Duplication
		$container->registerService('SettingsController', function(IContainer $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...
186
			/** @var \OC\Server $server */
187 2
			$server = $c->query('ServerContainer');
188
189 2
			return new Settings(
190 2
				$c->query('AppName'),
191 2
				$server->getRequest(),
192 2
				$server->getConfig(),
193 2
				$server->getSecureRandom()->getMediumStrengthGenerator(),
194 2
				$server->getURLGenerator(),
195 2
				$c->query('ActivityData'),
196 2
				$c->query('UserSettings'),
197 2
				$c->query('ActivityL10N'),
198 2
				$c->query('CurrentUID')
199
			);
200 26
		});
201
202 View Code Duplication
		$container->registerService('OCA\Activity\Controller\OCSEndPoint', function(IContainer $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...
203
			/** @var \OC\Server $server */
204
			$server = $c->query('ServerContainer');
205
206
			return new OCSEndPoint(
207
				$c->query('ActivityData'),
208
				$c->query('GroupHelper'),
209
				$c->query('UserSettings'),
210
				$server->getRequest(),
211
				$server->getURLGenerator(),
212
				$server->getUserSession(),
213
				$server->getPreviewManager(),
214
				$server->getMimeTypeDetector(),
215
				new View(''),
216
				$c->query('OCA\Activity\ViewInfoCache')
217
			);
218 26
		});
219
220
		$container->registerService('EndPointController', function(IContainer $c) {
221
			/** @var \OC\Server $server */
222
			$server = $c->query('ServerContainer');
223
224
			return new EndPoint(
225
				$c->query('AppName'),
226
				$server->getRequest(),
227
				$c->query('OCA\Activity\Controller\OCSEndPoint')
228
			);
229 26
		});
230
231
		$container->registerService('ActivitiesController', function(IContainer $c) {
232
			/** @var \OC\Server $server */
233 1
			$server = $c->query('ServerContainer');
234
235 1
			return new Activities(
236 1
				$c->query('AppName'),
237 1
				$server->getRequest(),
238 1
				$server->getConfig(),
239 1
				$c->query('ActivityData'),
240 1
				$c->query('Navigation')
241
			);
242 26
		});
243
244 26 View Code Duplication
		$container->registerService('FeedController', function(IContainer $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...
245
			/** @var \OC\Server $server */
246 1
			$server = $c->query('ServerContainer');
247
248 1
			return new Feed(
249 1
				$c->query('AppName'),
250 1
				$server->getRequest(),
251 1
				$c->query('ActivityData'),
252 1
				$c->query('GroupHelperSingleEntries'),
253 1
				$c->query('UserSettings'),
254 1
				$server->getURLGenerator(),
255 1
				$server->getActivityManager(),
256 1
				$server->getL10NFactory(),
257 1
				$server->getConfig(),
258 1
				$c->query('CurrentUID')
259
			);
260 26
		});
261 26
	}
262
}
263