Cancelled
Push — stable9 ( 48dd99...f67948 )
by Joas
685:53 queued 685:53
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 131
CRAP Score 3.0183

Importance

Changes 11
Bugs 0 Features 3
Metric Value
c 11
b 0
f 3
dl 50
loc 217
ccs 131
cts 150
cp 0.8733
rs 8.2857
cc 3
eloc 135
nc 1
nop 1
crap 3.0183

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