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

actions/friends/collections/edit.php (1 issue)

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

Bug Minor
1
<?php
2
/**
3
 * Friends collection edit action
4
 */
5
6
elgg_make_sticky_form('friends/collections/edit');
7
8
$collection_name = elgg_get_title_input('collection_name');
9
$friend_guids = (array) get_input('collection_friends', []);
10
$collection_id = get_input('collection_id');
11
12
if (!$collection_name) {
13
	return elgg_error_response(elgg_echo('friends:collections:edit:no_name'));
14
}
15
16
if (!$collection_id) {
17
	$collection_id = create_access_collection($collection_name, elgg_get_logged_in_user_guid(), 'friends_collection');
18
}
19
20
$collection = get_access_collection($collection_id);
0 ignored issues
show
It seems like $collection_id can also be of type string and false; however, parameter $collection_id of get_access_collection() 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

20
$collection = get_access_collection(/** @scrutinizer ignore-type */ $collection_id);
Loading history...
21
22
if (!$collection instanceof ElggAccessCollection || !$collection->canEdit()) {
23
	return elgg_error_response(elgg_echo('friends:collections:edit:permissions'));
24
}
25
26
if ($collection->name != $collection_name) {
27
	$collection->name = $collection_name;
28
	$collection->save();
29
}
30
31
$count = 0;
32
foreach ($friend_guids as $friend_guid) {
33
	if (!$collection->hasMember($friend_guid) && $collection->addMember($friend_guid)) {
34
		$count++;
35
	}
36
}
37
38
if ($count > 0) {
39
	elgg_clear_sticky_form('friends/collections/edit');
40
41
	$data = [
42
		'collection' => $collection,
43
		'count' => $count,
44
	];
45
	$msg = elgg_echo('friends:collections:edit:success', [$count]);
46
	return elgg_ok_response($data, $msg, $collection->getURL());
47
} else {
48
	return elgg_error_response(elgg_echo('friends:collections:edit:fail'));
49
}
50