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

mod/likes/actions/likes/delete.php (1 issue)

1
<?php
2
/**
3
 * Elgg delete like action
4
 *
5
 */
6
7
// Support deleting by id in case we're deleting another user's likes
8
$id = (int) get_input('id');
9
10
$like = null;
11
if ($id) {
12
	$like = elgg_get_annotation_from_id($id);
13
}
14
15
if (!$like) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $like of type null|false is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
16
	$likes = elgg_get_annotations([
17
		'guid' => (int) get_input('guid'),
18
		'annotation_owner_guid' => elgg_get_logged_in_user_guid(),
19
		'annotation_name' => 'likes',
20
	]);
21
	$like = $likes[0];
22
}
23
24
if (!$like || !$like->delete()) {
25
	return elgg_error_response(elgg_echo('likes:notdeleted'));
26
}
27
28
return elgg_ok_response('', elgg_echo('likes:deleted'));
29