Container::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 265
Code Lines 148

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 265
rs 8.2857
cc 1
eloc 148
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
 * Copyright (c) 2014, Tobia De Koninck hey--at--ledfan.be
4
 * This file is licensed under the AGPL version 3 or later.
5
 * See the COPYING file.
6
 */
7
8
namespace OCA\Chat\App;
9
10
use OCA\Chat\Controller\AppController;
11
use OCA\Chat\Controller\OCH\ApiController;
12
use OCA\Chat\Controller\ConfigController;
13
use OCA\Chat\Controller\AdminController;
14
use OCP\AppFramework\App;
15
use OCA\Chat\OCH\Db\ConversationMapper;
16
use OCA\Chat\OCH\Db\MessageMapper;
17
use OCA\Chat\OCH\Db\PushMessageMapper;
18
use OCA\Chat\OCH\Db\UserMapper;
19
use OCA\Chat\OCH\Db\UserOnlineMapper;
20
use OCA\Chat\OCH\Db\AttachmentMapper;
21
use OCA\Chat\Db\ConfigMapper;
22
use OCA\Chat\OCH\Commands\Greet;
23
use OCA\Chat\OCH\Commands\Invite;
24
use OCA\Chat\OCH\Commands\Join;
25
use OCA\Chat\OCH\Commands\Offline;
26
use OCA\Chat\OCH\Commands\Online;
27
use OCA\Chat\OCH\Commands\SendChatMsg;
28
use OCA\Chat\OCH\Commands\StartConv;
29
use OCA\Chat\OCH\Commands\SyncOnline;
30
use OCA\Chat\OCH\Commands\AttachFile;
31
use OCA\Chat\OCH\Commands\RemoveFile;
32
use OCA\Chat\OCH\Data\GetUsers;
33
use OCA\Chat\OCH\Data\Messages;
34
use OCA\Chat\OCH\Push\Get;
35
use OCA\Chat\OCH\Push\Delete;
36
use OCA\Chat\OCH\OCH;
37
use OCA\Chat\XMPP\XMPP;
38
use OCA\Chat\BackendManager;
39
use OCA\Chat\IBackend;
40
use OCA\Chat\Middleware\ErrorMiddleware;
41
42
/**
43
 * Class Chat
44
 * @package OCA\Chat\App
45
 */
46
class Container extends App{
47
48
	/**
49
	 * @param array $urlParams
50
	 */
51
	public function __construct(array $urlParams = array()) {
52
		parent::__construct('chat', $urlParams);
53
		$container = $this->getContainer();
54
		$container->registerMiddleware('ErrorMiddleware');
55
56
		/**
57
		 * Chat Class
58
		 */
59
		$container->registerService('Chat', function($c){
60
			return new Chat(
61
				$c->query('BackendManager'),
62
				$c->query('UserOnlineMapper'),
63
				$c->query('SyncOnlineCommand'),
64
				$c->query('UserId'),
65
				$c->query('OCP\Contacts\IManager'),
66
				$c->query('OCP\Files\IRootFolder')
67
			);
68
		});
69
70
		/**
71
		 * Controllers
72
		 */
73
		$container->registerService('AppController', function ($c) {
74
			return new AppController(
75
				$c->query('AppName'),
76
				$c->query('Request'),
77
				$c->query('Chat'),
78
				$c->query('OCP\Contacts\IManager'),
79
				$c->query('OCP\IConfig'),
80
				$c->query('GreetCommand')
81
			);
82
		});
83
84
		$container->registerService('ApiController', function ($c) {
85
			return new ApiController(
86
				$c->query('AppName'),
87
				$c->query('Request'),
88
				$c->query('Chat'),
89
				$this
90
			);
91
		});
92
93
		$container->registerService('ConfigController', function ($c) {
94
			return new ConfigController(
95
				$c->query('AppName'),
96
				$c->query('Request'),
97
				$c->query('ConfigMapper'),
98
				$c->query('BackendManager')
99
			);
100
		});
101
102
		$container->registerService('AdminController', function ($c) {
103
			return new AdminController(
104
				$c->query('AppName'),
105
				$c->query('Request'),
106
				$c->query('BackendManager')
107
			);
108
		});
109
110
		/**
111
		 * DataMappers
112
		 */
113
114
		$container->registerService('ConversationMapper', function ($c) {
115
			return new ConversationMapper(
116
				$c->query('OCP\IDb')
117
			);
118
		});
119
120
		$container->registerService('ConversationMapper', function ($c) {
121
			return new ConversationMapper(
122
				$c->query('OCP\IDb')
123
			);
124
		});
125
126
		$container->registerService('MessageMapper', function ($c) {
127
			return new MessageMapper(
128
				$c->query('OCP\IDb')
129
			);
130
		});
131
132
		$container->registerService('PushMessageMapper', function ($c) {
133
			return new PushMessageMapper(
134
				$c->query('OCP\IDb'),
135
				$c['UserOnlineMapper'],
136
				$c['UserMapper']
137
			);
138
		});
139
140
		$container->registerService('UserMapper', function ($c) {
141
			return new UserMapper(
142
				$c->query('OCP\IDb')
143
			);
144
		});
145
146
		$container->registerService('UserOnlineMapper', function ($c) {
147
			return new UserOnlineMapper(
148
				$c->query('OCP\IDb')
149
			);
150
		});
151
152
		$container->registerService('AttachmentMapper', function ($c) {
153
			return new AttachmentMapper(
154
				$c->query('OCP\IDb'),
155
				$c->query('Chat')
156
			);
157
		});
158
159
		$container->registerService('ConfigMapper', function ($c) {
160
			return new ConfigMapper(
161
				$c->query('OCP\IDb'),
162
				$c->query('Chat')->getUserId(),
163
				$c->query('OCP\Security\ICrypto')
164
			);
165
		});
166
167
		/**
168
		 * Command API Requests
169
		 */
170
		$container->registerService('GreetCommand', function ($c) {
171
			return new Greet(
172
				$c->query('PushMessageMapper'),
173
				$c->query('UserOnlineMapper')
174
			);
175
		});
176
177
		$container->registerService('InviteCommand', function ($c) {
178
			return new Invite(
179
				$c->query('PushMessageMapper'),
180
				$c->query('JoinCommand'),
181
				$c->query('GetUsersData')
182
			);
183
		});
184
185
		$container->registerService('JoinCommand', function ($c) {
186
			return new Join(
187
				$c->query('PushMessageMapper'),
188
				$c->query('GetUsersData'),
189
				$c->query('UserMapper')
190
			);
191
		});
192
193
		$container->registerService('OfflineCommand', function ($c) {
194
			return new Offline(
195
				$c->query('PushMessageMapper'),
196
				$c->query('UserOnlineMapper'),
197
				$c->query('SyncOnlineCommand')
198
			);
199
		});
200
201
		$container->registerService('OnlineCommand', function ($c) {
202
			return new Online(
203
				$c->query('UserOnlineMapper'),
204
				$c->query('SyncOnlineCommand')
205
			);
206
		});
207
208
		$container->registerService('SendChatMsgCommand', function ($c) {
209
			return new SendChatMsg(
210
				$c->query('PushMessageMapper'),
211
				$c->query('MessageMapper')
212
			);
213
		});
214
215
		$container->registerService('StartConvCommand', function ($c) {
216
			return new StartConv(
217
				$c->query('MessageMapper'),
218
				$c->query('ConversationMapper'),
219
				$c->query('InviteCommand'),
220
				$c->query('JoinCommand'),
221
				$c->query('GetUsersData'),
222
				$c->query('MessagesData')
223
			);
224
		});
225
226
227
		$container->registerService('SyncOnlineCommand', function ($c) {
228
			return new SyncOnline(
229
				$c->query('UserOnlineMapper')
230
			);
231
		});
232
233
		$container->registerService('AttachFileCommand', function ($c) {
234
			return new AttachFile(
235
				$c->query('Chat'),
236
				$c->query('UserMapper'),
237
				$c->query('AttachmentMapper'),
238
				$c->query('PushMessageMapper')
239
			);
240
		});
241
242
		$container->registerService('RemoveFileCommand', function ($c) {
243
			return new RemoveFile(
244
				$c->query('Chat'),
245
				$c->query('PushMessageMapper'),
246
				$c->query('AttachmentMapper'),
247
				$c->query('UserMapper')
248
			);
249
		});
250
251
252
		/**
253
		 * Push API Requests
254
		 */
255
		$container->registerService('GetPush', function ($c) {
256
			return new Get(
257
				$c->query('PushMessageMapper')
258
			);
259
		});
260
261
		$container->registerService('DeletePush', function ($c) {
262
			return new Delete(
263
				$c->query('PushMessageMapper')
264
			);
265
		});
266
267
		/**
268
		 * Data API Requests
269
		 */
270
		$container->registerService('GetUsersData', function ($c) {
271
			return new GetUsers(
272
				$c->query('Chat'),
273
				$c->query('UserMapper')
274
			);
275
		});
276
277
		$container->registerService('MessagesData', function ($c) {
278
			return new Messages(
279
				$c->query('MessageMapper')
280
			);
281
		});
282
283
		/**
284
		 * Manager
285
		 */
286
		$container->registerService('BackendManager', function($c){
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
287
			return new BackendManager();
288
		});
289
290
		$container->registerService('OCH', function($c){
291
			return new OCH(
292
				$c->query('ConfigMapper'),
293
				$c->query('OCP\IConfig'),
294
				$c->query('UserMapper'),
295
				$c->query('AttachmentMapper'),
296
				$c->query('StartConvCommand'),
297
				$c->query('MessagesData'),
298
				$c->query('JoinCommand'),
299
				$c->query('Chat')
300
			);
301
		});
302
303
		$container->registerService('XMPP', function($c){
304
			return new XMPP(
305
				$c->query('ConfigMapper'),
306
				$c->query('OCP\IConfig'),
307
				$c->query('Chat')
308
			);
309
		});
310
311
		$container->registerService('ErrorMiddleware', function($c){
312
			return new ErrorMiddleware($c->query('Chat'));
313
		});
314
315
	}
316
317
	public function query($param){
318
		return $this->getContainer()->query($param);
319
	}
320
321
}
322