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

views/default/page/elements/admin_notices.php (1 issue)

implicit conversion of array to boolean.

Best Practice Bug Minor
1
<?php
2
/**
3
 * Lists admin notices
4
 *
5
 * @uses $vars['notices'] Array of ElggObject notices
6
 */
7
8
if (!elgg_is_admin_logged_in() || !elgg_in_context('admin')) {
9
	return;
10
}
11
12
$count = elgg_get_admin_notices([
13
	'count' => true,
14
]);
15
16
if (!$count) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $count of type ElggObject[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
17
	return;
18
}
19
20
$button = '';
21
if ($count > 5) {
22
	$button = elgg_view('output/url', [
23
		'class' => 'elgg-admin-notices-dismiss-all',
24
		'text' => elgg_echo('admin:notices:delete_all', [$count]),
25
		'href' => 'action/admin/delete_admin_notices',
26
		'is_action' => true,
27
		'confirm' => true,
28
		'icon' => 'times',
29
	]);
30
}
31
32
$notices = elgg_get_admin_notices([
33
	'limit' => 5,
34
]);
35
36
$list = elgg_view_entity_list($notices, [
37
	'list_class' => 'elgg-admin-notices',
38
]);
39
40
echo elgg_view_module('admin-notices', ' ', $list, [
41
	'menu' => $button,
42
]);
43