Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

notifications/actions/notifications/settings.php (1 issue)

Checks if the types of the passed arguments in a function/method call are compatible.

Bug Minor
1
<?php
2
/**
3
 * Saves user notification settings
4
 */
5
6
$guid = get_input('guid');
7
$user = get_entity($guid);
0 ignored issues
show
It seems like $guid can also be of type string; however, parameter $guid of get_entity() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

7
$user = get_entity(/** @scrutinizer ignore-type */ $guid);
Loading history...
8
9
if (!$user || !$user->canEdit()) {
10
	return elgg_error_response(elgg_echo('actionunauthorized'), '', 403);
11
}
12
13
$methods = elgg_get_notification_methods();
14
if (empty($methods)) {
15
	return elgg_error_response('', REFERER, 404);
16
}
17
18
$personal_settings = (array) get_input('personal', []);
19
foreach ($methods as $method) {
20
	$user->setNotificationSetting($method, in_array($method, $personal_settings));
21
}
22
23
$collections_by_method = [];
24
25
$collection_settings = get_input('collections');
26
if ($collection_settings !== null) {
27
	if (!empty($collection_settings)) {
28
		foreach ($collection_settings as $collection_id => $preferred_methods) {
29
			if (!is_array($preferred_methods)) {
30
				$preferred_methods = [];
31
			}
32
			foreach ($preferred_methods as $preferred_method) {
33
				$collections_by_method[$preferred_method][] = $collection_id;
34
			}
35
		}
36
	}
37
38
	foreach ($methods as $method) {
39
		$metaname = 'collections_notifications_preferences_' . $method;
40
		$user->$metaname = array_unique($collections_by_method[$method]);
41
	}
42
}
43
44
return elgg_ok_response('', elgg_echo('notifications:subscriptions:success'));
45