Completed
Push — Readme-gmail-change ( 92e7ac )
by
unknown
02:28
created

Application::__construct()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 187
Code Lines 105

Duplication

Lines 29
Ratio 15.51 %

Code Coverage

Tests 23
CRAP Score 4.1249

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 29
loc 187
ccs 23
cts 121
cp 0.1901
rs 8.2857
cc 2
eloc 105
nc 1
nop 1
crap 4.1249

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
 * ownCloud - mail
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Thomas Müller <[email protected]>
9
 * @copyright Thomas Müller 2014
10
 */
11
12
namespace OCA\Mail\AppInfo;
13
14
use OCA\Mail\Controller\AccountsController;
15
use OCA\Mail\Controller\FoldersController;
16
use OCA\Mail\Controller\MessagesController;
17
use OCA\Mail\Controller\ProxyController;
18
use OCA\Mail\Db\MailAccountMapper;
19
use OCA\Mail\Service\AccountService;
20
use OCA\Mail\Service\AutoConfig\AutoConfig;
21
use OCA\Mail\Service\AutoConfig\ImapConnectivityTester;
22
use OCA\Mail\Service\AutoConfig\ImapConnector;
23
use OCA\Mail\Service\AutoConfig\ImapServerDetector;
24
use OCA\Mail\Service\AutoConfig\MozillaIspDb;
25
use OCA\Mail\Service\AutoConfig\MxRecord;
26
use OCA\Mail\Service\AutoConfig\SmtpConnectivityTester;
27
use OCA\Mail\Service\AutoConfig\SmtpServerDetector;
28
use OCA\Mail\Service\ContactsIntegration;
29
use OCA\Mail\Service\Logger;
30
use \OCP\AppFramework\App;
31
use \OCA\Mail\Controller\PageController;
32
use OCP\AppFramework\IAppContainer;
33
34
class Application extends App {
35
36 1
	public function __construct (array $urlParams=array()) {
37 1
		parent::__construct('mail', $urlParams);
38
39 1
		$container = $this->getContainer();
40
41
		/**
42
		 * Controllers
43
		 */
44
		$container->registerService('PageController', function($c) {
45
			/** @var IAppContainer $c */
46
			return new PageController(
47
				$c->query('AppName'),
48
				$c->query('Request'),
49
				$c->query('MailAccountMapper'),
50
				$c->query('ServerContainer')->getURLGenerator(),
51
				$c->query('UserId')
52
			);
53 1
		});
54
55
		$container->registerService('AccountService', function($c) {
56
			/** @var IAppContainer $c */
57
			return new AccountService(
58
				$c->query('MailAccountMapper'),
59
				$c->getServer()->getL10N('mail')
60
			);
61 1
		});
62
63 View Code Duplication
		$container->registerService('AccountsController', function($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...
64
			/** @var IAppContainer $c */
65
			return new AccountsController(
66
				$c->query('AppName'),
67
				$c->query('Request'),
68
				$c->query('AccountService'),
69
				$c->query('UserId'),
70
				$c->getServer()->getUserFolder(),
71
				$c->query('ContactsIntegration'),
72
				$c->query('AutoConfig'),
73
				$c->query('Logger'),
74
				$c->getServer()->getL10N('mail'),
75
				$c->getServer()->getCrypto()
76
			);
77 1
		});
78
79
		$container->registerService('FoldersController', function($c) {
80
			/** @var IAppContainer $c */
81
			return new FoldersController(
82
				$c->query('AppName'),
83
				$c->query('Request'),
84
				$c->query('AccountService'),
85
				$c->query('UserId')
86
			);
87 1
		});
88
89 View Code Duplication
		$container->registerService('MessagesController', function($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...
90
			/** @var IAppContainer $c */
91
			return new MessagesController(
92
				$c->query('AppName'),
93
				$c->query('Request'),
94
				$c->query('AccountService'),
95
				$c->query('UserId'),
96
				$c->getServer()->getUserFolder(),
97
				$c->query('ContactsIntegration'),
98
				$c->query('Logger'),
99
				$c->getServer()->getL10N('mail'),
100
				$c->getServer()->getMimeTypeDetector()
101
			);
102 1
		});
103
104
		$container->registerService('ProxyController', function($c) {
105
			/** @var IAppContainer $c */
106
			return new ProxyController(
107
				$c->query('AppName'),
108
				$c->query('Request'),
109
				$c->query('ServerContainer')->getURLGenerator(),
110
				$c->query('ServerContainer')->getSession(),
111
				$c->getServer()->getHelper(),
112
				isset($_SERVER['HTTP_REFERER']) ? : null,
113
				\OCP\Util::getServerHostName()
114
			);
115 1
		});
116
117
		/**
118
		 * Mappers
119
		 */
120
		$container->registerService('MailAccountMapper', function ($c) {
121
			/** @var IAppContainer $c */
122
			return new MailAccountMapper($c->getServer()->getDb());
123 1
		});
124
125
		/**
126
		 * Services
127
		 */
128
		$container->registerService('ContactsIntegration', function ($c) {
129
			/** @var IAppContainer $c */
130
			return new ContactsIntegration($c->getServer()->getContactsManager());
131 1
		});
132
133
		$container->registerService('ImapConnectivityTester', function($c) {
134
			/** @var IAppContainer $c */
135
			return new ImapConnectivityTester(
136
				$c->query('ImapConnector'),
137
				$c->query('Logger'),
138
				$c->query('UserId')
139
			);
140 1
		});
141
142
		$container->registerService('ImapConnector', function($c) {
143
			/** @var IAppContainer $c */
144
			return new ImapConnector(
145
				$c->getServer()->getCrypto(),
146
				$c->query('Logger'),
147
				$c->query('UserId')
148
			);
149 1
		});
150
151
		$container->registerService('ImapServerDetector', function($c) {
152
			/** @var IAppContainer $c */
153
			return new ImapServerDetector(
154
				$c->query('MxRecord'),
155
				$c->query('ImapConnectivityTester')
156
			);
157 1
		});
158
159
		$container->registerService('SmtpConnectivityTester', function($c) {
160
			/** @var IAppContainer $c */
161
			return new SmtpConnectivityTester(
162
				$c->getServer()->getCrypto(),
163
				$c->query('Logger'),
164
				$c->query('UserId')
165
			);
166 1
		});
167
168
		$container->registerService('SmtpServerDetector', function($c) {
169
			$transport = $c->getServer()->getConfig()->getSystemValue('app.mail.transport', 'smtp');
170
			/** @var IAppContainer $c */
171
			return new SmtpServerDetector(
172
				$c->query('MxRecord'),
173
				$c->query('SmtpConnectivityTester'),
174
				$transport === 'smtp'
175
			);
176 1
		});
177
178
		$container->registerService('MozillaIspDb', function($c) {
179
			/** @var IAppContainer $c */
180
			return new MozillaIspDb(
181
				$c->query('Logger')
182
			);
183 1
		});
184
185
		$container->registerService('MxRecord', function($c) {
186
			/** @var IAppContainer $c */
187
			return new MxRecord(
188
				$c->query('Logger')
189
			);
190 1
		});
191
192
		$container->registerService('AutoConfig', function ($c) {
193
			/** @var IAppContainer $c */
194
			return new AutoConfig(
195
				$c->query('Logger'),
196
				$c->query('UserId'),
197
				$c->query('MozillaIspDb'),
198
				$c->query('MxRecord'),
199
				$c->query('ImapConnectivityTester'),
200
				$c->query('ImapServerDetector'),
201
				$c->query('SmtpConnectivityTester'),
202
				$c->query('SmtpServerDetector'),
203
				$c->query('ImapConnector'),
204
				$c->getServer()->getCrypto()
205
			);
206 1
		});
207
208
		$container->registerService('Logger', function ($c) {
209
			/** @var IAppContainer $c */
210
			return new Logger(
211
				$c->query('AppName'),
212
				$c->query('ServerContainer')->getLogger()
213
			);
214 1
		});
215
216
		/**
217
		 * Core
218
		 */
219 1
		$container->registerService('UserId', function() {
220
			return \OCP\User::getUser();
221 1
		});
222 1
	}
223
224
}
225