Completed
Pull Request — master (#455)
by Joas
03:13
created

Application   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 207
Duplicated Lines 15.94 %

Coupling/Cohesion

Components 0
Dependencies 14

Test Coverage

Coverage 100%

Importance

Changes 12
Bugs 0 Features 4
Metric Value
wmc 3
c 12
b 0
f 4
lcom 0
cbo 14
dl 33
loc 207
ccs 129
cts 129
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 33 205 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
/**
4
 * ownCloud - Activity App
5
 *
6
 * @author Joas Schilling
7
 * @copyright 2014 Joas Schilling [email protected]
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
 * License as published by the Free Software Foundation; either
12
 * version 3 of the License, or any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public
20
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
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\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
			);
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
			);
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
				),
87 10
				$server->getL10NFactory(),
88 10
				$c->query('ActivityL10N')
89
			);
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 6
				true
97
			);
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 1
				false
105
			);
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
				$c->query('CurrentUID')
120
			);
121 26
		});
122
123
		$container->registerService('MailQueueHandler', function(IContainer $c) {
124
			/** @var \OC\Server $server */
125 2
			$server = $c->query('ServerContainer');
126
127 2
			return new MailQueueHandler(
128 2
				$server->getDateTimeFormatter(),
129 2
				$server->getDatabaseConnection(),
130 2
				$c->query('DataHelper'),
131 2
				$server->getMailer(),
132 2
				$server->getURLGenerator(),
133 2
				$server->getUserManager(),
134 2
				$server->getActivityManager()
135
			);
136 26
		});
137
138
		$container->registerService('Navigation', function(IContainer $c) {
139
			/** @var \OC\Server $server */
140 2
			$server = $c->query('ServerContainer');
141 2
			$rssToken = ($c->query('CurrentUID') !== '') ? $server->getConfig()->getUserValue($c->query('CurrentUID'), 'activity', 'rsstoken') : '';
142
143 2
			return new Navigation(
144 2
				$c->query('ActivityL10N'),
145 2
				$server->getActivityManager(),
146 2
				$server->getURLGenerator(),
147 2
				$c->query('UserSettings'),
148 2
				$c->query('CurrentUID'),
149
				$rssToken
150
			);
151 26
		});
152
153
		$container->registerService('UserSettings', function(IContainer $c) {
154
			/** @var \OC\Server $server */
155 14
			$server = $c->query('ServerContainer');
156 14
			return new UserSettings(
157 14
				$server->getActivityManager(),
158 14
				$server->getConfig(),
159 14
				$c->query('ActivityData')
160
			);
161 26
		});
162
163
		$container->registerService('OCA\Activity\ViewInfoCache', function() {
164 11
			return new ViewInfoCache(
165 11
				new View('')
166
			);
167 26
		});
168
169
		/**
170
		 * Core Services
171
		 */
172
		$container->registerService('CurrentUID', function(IContainer $c) {
173
			/** @var \OC\Server $server */
174 15
			$server = $c->query('ServerContainer');
175
176 15
			$user = $server->getUserSession()->getUser();
177 15
			return ($user) ? $user->getUID() : '';
178 26
		});
179
180
		/**
181
		 * Controller
182
		 */
183 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...
184
			/** @var \OC\Server $server */
185 2
			$server = $c->query('ServerContainer');
186
187 2
			return new Settings(
188 2
				$c->query('AppName'),
189 2
				$server->getRequest(),
190 2
				$server->getConfig(),
191 2
				$server->getSecureRandom()->getMediumStrengthGenerator(),
192 2
				$server->getURLGenerator(),
193 2
				$c->query('ActivityData'),
194 2
				$c->query('UserSettings'),
195 2
				$c->query('ActivityL10N'),
196 2
				$c->query('CurrentUID')
197
			);
198 26
		});
199
200
		$container->registerService('OCA\Activity\Controller\OCSEndPoint', function(IContainer $c) {
201
			/** @var \OC\Server $server */
202 1
			$server = $c->query('ServerContainer');
203
204 1
			return new OCSEndPoint(
205 1
				$c->query('ActivityData'),
206 1
				$c->query('GroupHelper'),
207 1
				$c->query('UserSettings'),
208 1
				$server->getRequest(),
209 1
				$server->getURLGenerator(),
210 1
				$server->getUserSession(),
211 1
				$server->getPreviewManager(),
212 1
				$server->getMimeTypeDetector(),
213 1
				new View(''),
214 1
				$c->query('OCA\Activity\ViewInfoCache')
215
			);
216 26
		});
217
218
		$container->registerService('ActivitiesController', function(IContainer $c) {
219
			/** @var \OC\Server $server */
220 1
			$server = $c->query('ServerContainer');
221
222 1
			return new Activities(
223 1
				$c->query('AppName'),
224 1
				$server->getRequest(),
225 1
				$server->getConfig(),
226 1
				$c->query('ActivityData'),
227 1
				$c->query('Navigation')
228
			);
229 26
		});
230
231 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...
232
			/** @var \OC\Server $server */
233 1
			$server = $c->query('ServerContainer');
234
235 1
			return new Feed(
236 1
				$c->query('AppName'),
237 1
				$server->getRequest(),
238 1
				$c->query('ActivityData'),
239 1
				$c->query('GroupHelperSingleEntries'),
240 1
				$c->query('UserSettings'),
241 1
				$server->getURLGenerator(),
242 1
				$server->getActivityManager(),
243 1
				$server->getL10NFactory(),
244 1
				$server->getConfig(),
245 1
				$c->query('CurrentUID')
246
			);
247 26
		});
248 26
	}
249
}
250