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

views/default/river/elements/responses.php (1 issue)

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

Bug Minor
1
<?php
2
/**
3
 * River item footer
4
 *
5
 * @uses $vars['item'] ElggRiverItem
6
 * @uses $vars['responses'] Alternate override for this item
7
 */
8
9
// allow river views to override the response content
10
$responses = elgg_extract('responses', $vars);
11
if (isset($responses)) {
12
	echo $responses;
13
	return;
14
}
15
16
$item = elgg_extract('item', $vars);
17
if (!$item instanceof ElggRiverItem) {
18
	return;
19
}
20
21
$object = $item->getObjectEntity();
22
23
// annotations and comments do not have responses
24
if (!empty($item->annotation_id) || !$object instanceof ElggEntity || $object instanceof ElggComment) {
25
	return;
26
}
27
28
$comment_count = $object->countComments();
29
30
if ($comment_count) {
31
	$comments = elgg_get_entities([
32
		'type' => 'object',
33
		'subtype' => 'comment',
34
		'container_guid' => $object->getGUID(),
35
		'limit' => 3,
36
		'order_by' => 'e.time_created desc',
37
		'distinct' => false,
38
	]);
39
40
	// why is this reversing it? because we're asking for the 3 latest
41
	// comments by sorting desc and limiting by 3, but we want to display
42
	// these comments with the latest at the bottom.
43
	$comments = array_reverse($comments);
0 ignored issues
show
It seems like $comments can also be of type integer and false; however, parameter $array of array_reverse() does only seem to accept array, 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

43
	$comments = array_reverse(/** @scrutinizer ignore-type */ $comments);
Loading history...
44
	
45
	echo elgg_view_entity_list($comments, [
46
		'list_class' => 'elgg-river-comments',
47
		'show_excerpt' => true,
48
	]);
49
	
50
	if ($comment_count > count($comments)) {
51
		echo elgg_format_element('div', ['class' => 'elgg-river-more'], elgg_view('output/url', [
52
			'href' => $object->getURL(),
53
			'text' => elgg_echo('river:comments:all', [$comment_count]),
54
			'is_trusted' => true,
55
		]));
56
	}
57
}
58
59
if (!$object->canComment()) {
60
	return;
61
}
62
63
// inline comment form
64
$form_vars = ['id' => "comments-add-{$object->guid}-{$item->id}", 'class' => 'hidden'];
65
$body_vars = ['entity' => $object, 'inline' => true];
66
echo elgg_view_form('comment/save', $form_vars, $body_vars);
67