Passed
Push — master ( 12ed5c...f4135c )
by Julius
17:07 queued 12s
created

Application   C

Complexity

Total Complexity 53

Size/Duplication

Total Lines 256
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 140
dl 0
loc 256
rs 6.96
c 0
b 0
f 0
wmc 53

1 Method

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 255 53

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
namespace OC\Core;
33
34
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
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\UserDeletedFilesCleanupListener;
41
use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
42
use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
43
use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
44
use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
45
use OC\Core\Notification\CoreNotifier;
46
use OC\DB\Connection;
47
use OC\DB\MissingColumnInformation;
48
use OC\DB\MissingIndexInformation;
49
use OC\DB\MissingPrimaryKeyInformation;
50
use OC\DB\SchemaWrapper;
51
use OC\Metadata\FileEventListener;
52
use OCP\AppFramework\App;
53
use OCP\EventDispatcher\IEventDispatcher;
54
use OCP\Files\Events\Node\NodeDeletedEvent;
55
use OCP\Files\Events\Node\NodeWrittenEvent;
56
use OCP\Files\Events\NodeRemovedFromCache;
57
use OCP\IDBConnection;
58
use OCP\User\Events\BeforeUserDeletedEvent;
59
use OCP\User\Events\UserDeletedEvent;
60
use OCP\Util;
61
use OCP\IConfig;
62
use Symfony\Component\EventDispatcher\GenericEvent;
63
64
/**
65
 * Class Application
66
 *
67
 * @package OC\Core
68
 */
69
class Application extends App {
70
	public function __construct() {
71
		parent::__construct('core');
72
73
		$container = $this->getContainer();
74
75
		$container->registerService('defaultMailAddress', function () {
76
			return Util::getDefaultEmailAddress('lostpassword-noreply');
77
		});
78
79
		$server = $container->getServer();
80
		/** @var IEventDispatcher $eventDispatcher */
81
		$eventDispatcher = $server->query(IEventDispatcher::class);
82
83
		$notificationManager = $server->getNotificationManager();
84
		$notificationManager->registerNotifierService(CoreNotifier::class);
85
		$notificationManager->registerNotifierService(AuthenticationNotifier::class);
86
87
		$oldEventDispatcher = $server->getEventDispatcher();
88
89
		$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

89
		$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...
90
			function (GenericEvent $event) use ($container) {
91
				/** @var MissingIndexInformation $subject */
92
				$subject = $event->getSubject();
93
94
				$schema = new SchemaWrapper($container->query(Connection::class));
95
96
				if ($schema->hasTable('share')) {
97
					$table = $schema->getTable('share');
98
99
					if (!$table->hasIndex('share_with_index')) {
100
						$subject->addHintForMissingSubject($table->getName(), 'share_with_index');
101
					}
102
					if (!$table->hasIndex('parent_index')) {
103
						$subject->addHintForMissingSubject($table->getName(), 'parent_index');
104
					}
105
					if (!$table->hasIndex('owner_index')) {
106
						$subject->addHintForMissingSubject($table->getName(), 'owner_index');
107
					}
108
					if (!$table->hasIndex('initiator_index')) {
109
						$subject->addHintForMissingSubject($table->getName(), 'initiator_index');
110
					}
111
				}
112
113
				if ($schema->hasTable('filecache')) {
114
					$table = $schema->getTable('filecache');
115
116
					if (!$table->hasIndex('fs_mtime')) {
117
						$subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
118
					}
119
120
					if (!$table->hasIndex('fs_size')) {
121
						$subject->addHintForMissingSubject($table->getName(), 'fs_size');
122
					}
123
124
					if (!$table->hasIndex('fs_id_storage_size')) {
125
						$subject->addHintForMissingSubject($table->getName(), 'fs_id_storage_size');
126
					}
127
128
					if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
129
						$subject->addHintForMissingSubject($table->getName(), 'fs_storage_path_prefix');
130
					}
131
				}
132
133
				if ($schema->hasTable('twofactor_providers')) {
134
					$table = $schema->getTable('twofactor_providers');
135
136
					if (!$table->hasIndex('twofactor_providers_uid')) {
137
						$subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
138
					}
139
				}
140
141
				if ($schema->hasTable('login_flow_v2')) {
142
					$table = $schema->getTable('login_flow_v2');
143
144
					if (!$table->hasIndex('poll_token')) {
145
						$subject->addHintForMissingSubject($table->getName(), 'poll_token');
146
					}
147
					if (!$table->hasIndex('login_token')) {
148
						$subject->addHintForMissingSubject($table->getName(), 'login_token');
149
					}
150
					if (!$table->hasIndex('timestamp')) {
151
						$subject->addHintForMissingSubject($table->getName(), 'timestamp');
152
					}
153
				}
154
155
				if ($schema->hasTable('whats_new')) {
156
					$table = $schema->getTable('whats_new');
157
158
					if (!$table->hasIndex('version')) {
159
						$subject->addHintForMissingSubject($table->getName(), 'version');
160
					}
161
				}
162
163
				if ($schema->hasTable('cards')) {
164
					$table = $schema->getTable('cards');
165
166
					if (!$table->hasIndex('cards_abid')) {
167
						$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
168
					}
169
170
					if (!$table->hasIndex('cards_abiduri')) {
171
						$subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
172
					}
173
				}
174
175
				if ($schema->hasTable('cards_properties')) {
176
					$table = $schema->getTable('cards_properties');
177
178
					if (!$table->hasIndex('cards_prop_abid')) {
179
						$subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
180
					}
181
				}
182
183
				if ($schema->hasTable('calendarobjects_props')) {
184
					$table = $schema->getTable('calendarobjects_props');
185
186
					if (!$table->hasIndex('calendarobject_calid_index')) {
187
						$subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
188
					}
189
				}
190
191
				if ($schema->hasTable('schedulingobjects')) {
192
					$table = $schema->getTable('schedulingobjects');
193
					if (!$table->hasIndex('schedulobj_principuri_index')) {
194
						$subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
195
					}
196
				}
197
198
				if ($schema->hasTable('properties')) {
199
					$table = $schema->getTable('properties');
200
					if (!$table->hasIndex('properties_path_index')) {
201
						$subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
202
					}
203
					if (!$table->hasIndex('properties_pathonly_index')) {
204
						$subject->addHintForMissingSubject($table->getName(), 'properties_pathonly_index');
205
					}
206
				}
207
208
				if ($schema->hasTable('jobs')) {
209
					$table = $schema->getTable('jobs');
210
					if (!$table->hasIndex('job_lastcheck_reserved')) {
211
						$subject->addHintForMissingSubject($table->getName(), 'job_lastcheck_reserved');
212
					}
213
				}
214
215
				if ($schema->hasTable('direct_edit')) {
216
					$table = $schema->getTable('direct_edit');
217
					if (!$table->hasIndex('direct_edit_timestamp')) {
218
						$subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp');
219
					}
220
				}
221
222
				if ($schema->hasTable('preferences')) {
223
					$table = $schema->getTable('preferences');
224
					if (!$table->hasIndex('preferences_app_key')) {
225
						$subject->addHintForMissingSubject($table->getName(), 'preferences_app_key');
226
					}
227
				}
228
			}
229
		);
230
231
		$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

231
		$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...
232
			function (GenericEvent $event) use ($container) {
233
				/** @var MissingPrimaryKeyInformation $subject */
234
				$subject = $event->getSubject();
235
236
				$schema = new SchemaWrapper($container->query(Connection::class));
237
238
				if ($schema->hasTable('federated_reshares')) {
239
					$table = $schema->getTable('federated_reshares');
240
241
					if (!$table->hasPrimaryKey()) {
242
						$subject->addHintForMissingSubject($table->getName());
243
					}
244
				}
245
246
				if ($schema->hasTable('systemtag_object_mapping')) {
247
					$table = $schema->getTable('systemtag_object_mapping');
248
249
					if (!$table->hasPrimaryKey()) {
250
						$subject->addHintForMissingSubject($table->getName());
251
					}
252
				}
253
254
				if ($schema->hasTable('comments_read_markers')) {
255
					$table = $schema->getTable('comments_read_markers');
256
257
					if (!$table->hasPrimaryKey()) {
258
						$subject->addHintForMissingSubject($table->getName());
259
					}
260
				}
261
262
				if ($schema->hasTable('collres_resources')) {
263
					$table = $schema->getTable('collres_resources');
264
265
					if (!$table->hasPrimaryKey()) {
266
						$subject->addHintForMissingSubject($table->getName());
267
					}
268
				}
269
270
				if ($schema->hasTable('collres_accesscache')) {
271
					$table = $schema->getTable('collres_accesscache');
272
273
					if (!$table->hasPrimaryKey()) {
274
						$subject->addHintForMissingSubject($table->getName());
275
					}
276
				}
277
278
				if ($schema->hasTable('filecache_extended')) {
279
					$table = $schema->getTable('filecache_extended');
280
281
					if (!$table->hasPrimaryKey()) {
282
						$subject->addHintForMissingSubject($table->getName());
283
					}
284
				}
285
			}
286
		);
287
288
		$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

288
		$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...
289
			function (GenericEvent $event) use ($container) {
290
				/** @var MissingColumnInformation $subject */
291
				$subject = $event->getSubject();
292
293
				$schema = new SchemaWrapper($container->query(Connection::class));
294
295
				if ($schema->hasTable('comments')) {
296
					$table = $schema->getTable('comments');
297
298
					if (!$table->hasColumn('reference_id')) {
299
						$subject->addHintForMissingColumn($table->getName(), 'reference_id');
300
					}
301
				}
302
			}
303
		);
304
305
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
306
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
307
		$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
308
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
309
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
310
		$eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
311
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
312
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
313
		$eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
314
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
315
		$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
316
317
		// Metadata
318
		/** @var IConfig $config */
319
		$config = $container->get(IConfig::class);
320
		if ($config->getSystemValueBool('enable_file_metadata', true)) {
321
			$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
322
			$eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class);
323
			$eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class);
324
			$eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class);
325
		}
326
	}
327
}
328