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

AjaxResponseHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
ccs 0
cts 13
cp 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
1
<?php
2
3
namespace Elgg\Likes;
4
5
use Elgg\Services\AjaxResponse;
6
7
/**
8
 * Ajax response handler
9
 */
10
class AjaxResponseHandler {
11
12
	/**
13
	 * Alter ajax response to send back likes count
14
	 *
15
	 * @param string                      $hook     Hook name (AjaxResponse::RESPONSE_HOOK)
16
	 * @param string                      $type     'all'
17
	 * @param \Elgg\Services\AjaxResponse $response Ajax response
18
	 * @param array                       $params   Hook params
19
	 *
20
	 * @return void|\Elgg\Services\AjaxResponse
21
	 */
22
	public function __invoke($hook, $type, AjaxResponse $response, $params) {
23
		$entity = get_entity(get_input('guid'));
0 ignored issues
show
Bug introduced by Steve Clay
It seems like get_input('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

23
		$entity = get_entity(/** @scrutinizer ignore-type */ get_input('guid'));
Loading history...
24
		if (!$entity) {
25
			return;
26
		}
27
		
28
		$response->getData()->likes_status = [
29
			'guid' => $entity->guid,
30
			'count' => likes_count($entity),
31
			'count_menu_item' => elgg_view_menu_item(_likes_count_menu_item($entity)),
32
			'like_menu_item' => elgg_view_menu_item(_likes_menu_item($entity)),
33
			'is_liked' => DataService::instance()->currentUserLikesEntity($entity->guid),
34
		];
35
		
36
		return $response;
37
	}
38
}
39