Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

views/default/widgets/content_stats/content.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Content stats widget
4
 */
5
6
$widget = elgg_extract('entity', $vars);
7
8
$entity_stats = get_entity_statistics();
9
10
$registered_entity_types = get_registered_entity_types();
11
12
foreach ($registered_entity_types as $type => $subtypes) {
0 ignored issues
show
The expression $registered_entity_types of type array|false is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
13
	if (!empty($subtypes)) {
14
		foreach ($subtypes as $subtype) {
15
			$value = elgg_extract($subtype, $entity_stats[$type], false);
16
			if ($value !== false) {
17
				$stats[elgg_echo("item:$type:$subtype")] = $value;
18
			}
19
		}
20
	} else {
21
		$value = elgg_extract('__base__', $entity_stats[$type], false);
22
		if ($value !== false) {
23
			$stats[elgg_echo("item:$type")] = $value;
24
		}
25
	}
26
}
27
28
arsort($stats);
29
30
echo '<table class="elgg-table-alt">';
31
echo '<tr><th>' . elgg_echo('admin:statistics:numentities:type') . '</th>';
32
echo '<th>' . elgg_echo('admin:statistics:numentities:number') . '</th></tr>';
33
foreach ($stats as $name => $num) {
34
	echo "<tr><td>$name</td><td>$num</td></tr>";
35
}
36
echo '</table>';
37
38
echo '<div class="mtm elgg-widget-more">';
39
echo elgg_view('output/url', [
40
	'href' => 'admin/statistics/numentities',
41
	'text' => elgg_echo('more'),
42
	'is_trusted' => true,
43
]);
44
echo '</div>';
45