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

mod/friends/actions/friends/add.php (1 issue)

1
<?php
2
/**
3
 * Elgg add friend action
4
 */
5
6
// Get the GUID of the user to friend
7
$friend_guid = get_input('friend');
8
$friend = get_user($friend_guid);
0 ignored issues
show
It seems like $friend_guid can also be of type string; however, parameter $guid of get_user() 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

8
$friend = get_user(/** @scrutinizer ignore-type */ $friend_guid);
Loading history...
9
10
if (!$friend instanceof \ElggUser) {
11
	return elgg_error_response(elgg_echo('error:missing_data'));
12
}
13
14
if (!elgg_get_logged_in_user_entity()->addFriend($friend->guid, true)) {
15
	return elgg_error_response(elgg_echo('friends:add:failure', [$friend->getDisplayName()]));
16
}
17
18
return elgg_ok_response('', elgg_echo('friends:add:successful', [$friend->getDisplayName()]));
19