Passed
Push — master ( cdb1d3...2cae54 )
by Morris
12:34 queued 10s
created

Application   B

Complexity

Total Complexity 43

Size/Duplication

Total Lines 216
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 115
c 0
b 0
f 0
dl 0
loc 216
rs 8.96
wmc 43

1 Method

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 215 43

How to fix   Complexity   

Complex Class

Complex classes like Application often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Application, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 * @copyright Copyright (c) 2016 Joas Schilling <[email protected]>
5
 *
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Julius Härtl <[email protected]>
9
 * @author Lukas Reschke <[email protected]>
10
 * @author Mario Danic <[email protected]>
11
 * @author Morris Jobke <[email protected]>
12
 * @author Robin Appelman <[email protected]>
13
 * @author Roeland Jago Douma <[email protected]>
14
 * @author Thomas Citharel <[email protected]>
15
 * @author Victor Dubiniuk <[email protected]>
16
 *
17
 * @license AGPL-3.0
18
 *
19
 * This code is free software: you can redistribute it and/or modify
20
 * it under the terms of the GNU Affero General Public License, version 3,
21
 * as published by the Free Software Foundation.
22
 *
23
 * This program is distributed in the hope that it will be useful,
24
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
 * GNU Affero General Public License for more details.
27
 *
28
 * You should have received a copy of the GNU Affero General Public License, version 3,
29
 * along with this program. If not, see <http://www.gnu.org/licenses/>
30
 *
31
 */
32
33
namespace OC\Core;
34
35
use OC\Authentication\Events\RemoteWipeFinished;
36
use OC\Authentication\Events\RemoteWipeStarted;
37
use OC\Authentication\Listeners\RemoteWipeActivityListener;
38
use OC\Authentication\Listeners\RemoteWipeEmailListener;
39
use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
40
use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
41
use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
42
use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
43
use OC\Core\Notification\CoreNotifier;
44
use OC\DB\Connection;
45
use OC\DB\MissingColumnInformation;
46
use OC\DB\MissingIndexInformation;
47
use OC\DB\MissingPrimaryKeyInformation;
48
use OC\DB\SchemaWrapper;
49
use OCP\AppFramework\App;
50
use OCP\EventDispatcher\IEventDispatcher;
51
use OCP\IDBConnection;
52
use OCP\User\Events\UserDeletedEvent;
53
use OCP\Util;
54
use Symfony\Component\EventDispatcher\GenericEvent;
55
56
/**
57
 * Class Application
58
 *
59
 * @package OC\Core
60
 */
61
class Application extends App {
62
	public function __construct() {
63
		parent::__construct('core');
64
65
		$container = $this->getContainer();
66
67
		$container->registerService('defaultMailAddress', function () {
68
			return Util::getDefaultEmailAddress('lostpassword-noreply');
69
		});
70
71
		$server = $container->getServer();
72
		/** @var IEventDispatcher $eventDispatcher */
73
		$eventDispatcher = $server->query(IEventDispatcher::class);
74
75
		$notificationManager = $server->getNotificationManager();
76
		$notificationManager->registerNotifierService(CoreNotifier::class);
77
		$notificationManager->registerNotifierService(AuthenticationNotifier::class);
78
79
		$oldEventDispatcher = $server->getEventDispatcher();
80
81
		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\IDBConnection::CHECK_MISSING_INDEXES_EVENT has been deprecated: 22.0.0 this is an internal event ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

81
		$oldEventDispatcher->addListener(/** @scrutinizer ignore-deprecated */ IDBConnection::CHECK_MISSING_INDEXES_EVENT,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
82
			function (GenericEvent $event) use ($container) {
83
				/** @var MissingIndexInformation $subject */
84
				$subject = $event->getSubject();
85
86
				$schema = new SchemaWrapper($container->query(Connection::class));
87
88
				if ($schema->hasTable('share')) {
89
					$table = $schema->getTable('share');
90
91
					if (!$table->hasIndex('share_with_index')) {
92
						$subject->addHintForMissingSubject($table->getName(), 'share_with_index');
93
					}
94
					if (!$table->hasIndex('parent_index')) {
95
						$subject->addHintForMissingSubject($table->getName(), 'parent_index');
96
					}
97
					if (!$table->hasIndex('owner_index')) {
98
						$subject->addHintForMissingSubject($table->getName(), 'owner_index');
99
					}
100
					if (!$table->hasIndex('initiator_index')) {
101
						$subject->addHintForMissingSubject($table->getName(), 'initiator_index');
102
					}
103
				}
104
105
				if ($schema->hasTable('filecache')) {
106
					$table = $schema->getTable('filecache');
107
108
					if (!$table->hasIndex('fs_mtime')) {
109
						$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
110
					}
111
112
					if (!$table->hasIndex('fs_size')) {
113
						$subject->addHintForMissingSubject($table->getName(), 'fs_size');
114
					}
115
116
					if (!$table->hasIndex('fs_path_prefix')) {
117
						$subject->addHintForMissingSubject($table->getName(), 'fs_path_prefix');
118
					}
119
				}
120
121
				if ($schema->hasTable('twofactor_providers')) {
122
					$table = $schema->getTable('twofactor_providers');
123
124
					if (!$table->hasIndex('twofactor_providers_uid')) {
125
						$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
126
					}
127
				}
128
129
				if ($schema->hasTable('login_flow_v2')) {
130
					$table = $schema->getTable('login_flow_v2');
131
132
					if (!$table->hasIndex('poll_token')) {
133
						$subject->addHintForMissingSubject($table->getName(), 'poll_token');
134
					}
135
					if (!$table->hasIndex('login_token')) {
136
						$subject->addHintForMissingSubject($table->getName(), 'login_token');
137
					}
138
					if (!$table->hasIndex('timestamp')) {
139
						$subject->addHintForMissingSubject($table->getName(), 'timestamp');
140
					}
141
				}
142
143
				if ($schema->hasTable('whats_new')) {
144
					$table = $schema->getTable('whats_new');
145
146
					if (!$table->hasIndex('version')) {
147
						$subject->addHintForMissingSubject($table->getName(), 'version');
148
					}
149
				}
150
151
				if ($schema->hasTable('cards')) {
152
					$table = $schema->getTable('cards');
153
154
					if (!$table->hasIndex('cards_abid')) {
155
						$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
156
					}
157
158
					if (!$table->hasIndex('cards_abiduri')) {
159
						$subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
160
					}
161
				}
162
163
				if ($schema->hasTable('cards_properties')) {
164
					$table = $schema->getTable('cards_properties');
165
166
					if (!$table->hasIndex('cards_prop_abid')) {
167
						$subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
168
					}
169
				}
170
171
				if ($schema->hasTable('calendarobjects_props')) {
172
					$table = $schema->getTable('calendarobjects_props');
173
174
					if (!$table->hasIndex('calendarobject_calid_index')) {
175
						$subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
176
					}
177
				}
178
179
				if ($schema->hasTable('schedulingobjects')) {
180
					$table = $schema->getTable('schedulingobjects');
181
					if (!$table->hasIndex('schedulobj_principuri_index')) {
182
						$subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
183
					}
184
				}
185
186
				if ($schema->hasTable('properties')) {
187
					$table = $schema->getTable('properties');
188
					if (!$table->hasIndex('properties_path_index')) {
189
						$subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
190
					}
191
				}
192
			}
193
		);
194
195
		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\IDBConnection::CHECK...SING_PRIMARY_KEYS_EVENT has been deprecated: 22.0.0 this is an internal event ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

195
		$oldEventDispatcher->addListener(/** @scrutinizer ignore-deprecated */ IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
196
			function (GenericEvent $event) use ($container) {
197
				/** @var MissingPrimaryKeyInformation $subject */
198
				$subject = $event->getSubject();
199
200
				$schema = new SchemaWrapper($container->query(Connection::class));
201
202
				if ($schema->hasTable('federated_reshares')) {
203
					$table = $schema->getTable('federated_reshares');
204
205
					if (!$table->hasPrimaryKey()) {
206
						$subject->addHintForMissingSubject($table->getName());
207
					}
208
				}
209
210
				if ($schema->hasTable('systemtag_object_mapping')) {
211
					$table = $schema->getTable('systemtag_object_mapping');
212
213
					if (!$table->hasPrimaryKey()) {
214
						$subject->addHintForMissingSubject($table->getName());
215
					}
216
				}
217
218
				if ($schema->hasTable('comments_read_markers')) {
219
					$table = $schema->getTable('comments_read_markers');
220
221
					if (!$table->hasPrimaryKey()) {
222
						$subject->addHintForMissingSubject($table->getName());
223
					}
224
				}
225
226
				if ($schema->hasTable('collres_resources')) {
227
					$table = $schema->getTable('collres_resources');
228
229
					if (!$table->hasPrimaryKey()) {
230
						$subject->addHintForMissingSubject($table->getName());
231
					}
232
				}
233
234
				if ($schema->hasTable('collres_accesscache')) {
235
					$table = $schema->getTable('collres_accesscache');
236
237
					if (!$table->hasPrimaryKey()) {
238
						$subject->addHintForMissingSubject($table->getName());
239
					}
240
				}
241
242
				if ($schema->hasTable('filecache_extended')) {
243
					$table = $schema->getTable('filecache_extended');
244
245
					if (!$table->hasPrimaryKey()) {
246
						$subject->addHintForMissingSubject($table->getName());
247
					}
248
				}
249
			}
250
		);
251
252
		$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\IDBConnection::CHECK_MISSING_COLUMNS_EVENT has been deprecated: 22.0.0 this is an internal event ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

252
		$oldEventDispatcher->addListener(/** @scrutinizer ignore-deprecated */ IDBConnection::CHECK_MISSING_COLUMNS_EVENT,

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
253
			function (GenericEvent $event) use ($container) {
254
				/** @var MissingColumnInformation $subject */
255
				$subject = $event->getSubject();
256
257
				$schema = new SchemaWrapper($container->query(Connection::class));
258
259
				if ($schema->hasTable('comments')) {
260
					$table = $schema->getTable('comments');
261
262
					if (!$table->hasColumn('reference_id')) {
263
						$subject->addHintForMissingColumn($table->getName(), 'reference_id');
264
					}
265
				}
266
			}
267
		);
268
269
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
270
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
271
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
272
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
273
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
274
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
275
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
276
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
277
	}
278
}
279