From 06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Nov 2023 14:47:55 +0100 Subject: Add function param/return types, fix a lot more phpstorm complaints --- modules-available/statistics/pages/list.inc.php | 17 +-------- modules-available/statistics/pages/machine.inc.php | 4 +- modules-available/statistics/pages/summary.inc.php | 43 ++++++---------------- 3 files changed, 16 insertions(+), 48 deletions(-) (limited to 'modules-available/statistics/pages') diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php index 12689e97..b318cc68 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -22,10 +22,7 @@ class SubPage } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showMachineList(StatisticsFilterSet $filterSet) + private static function showMachineList(StatisticsFilterSet $filterSet): void { Module::isAvailable('js_stupidtable'); $filterSet->makeFragments($where, $join, $args); @@ -160,7 +157,7 @@ class SubPage $roomsvg = null; $side = []; if (!empty($rows) && !empty($colValCount)) { - if (count($colValCount['locationid']) === 1 && ($lid = array_key_first($colValCount['locationid'])) + if (count($colValCount['locationid']) === 1 && ($lid = array_key_first($colValCount['locationid'])) !== null && Module::isAvailable('roomplanner')) { $roomsvg = PvsGenerator::generateSvg($lid, false, 0, 1, true, $colValCount['locationid'][$lid]); } @@ -216,14 +213,4 @@ class SubPage return $ret; } -} - -// Remove when we require >= 7.3.0 -if (!function_exists('array_key_first')) { - function array_key_first(array $arr) { - foreach($arr as $key => $unused) { - return $key; - } - return NULL; - } } \ No newline at end of file diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index 2250c4b9..24bf7c1e 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -686,9 +686,9 @@ class SubPage } if (!is_array($json) || !isset($json['system'])) return ['error' => 'Malformed JSON, no system key']; - if (isset($json['system'][$system]) && isset($json['system'][$system]['fixes']) && isset($json['system'][$system]['match'])) { + if (isset($json['system'][$system]['fixes']) && isset($json['system'][$system]['match'])) { $match =& $json['system'][$system]; - } elseif (isset($json['mainboard'][$mainboard]) && isset($json['mainboard'][$mainboard]['fixes']) && isset($json['mainboard'][$mainboard]['match'])) { + } elseif (isset($json['mainboard'][$mainboard]['fixes']) && isset($json['mainboard'][$mainboard]['match'])) { $match =& $json['mainboard'][$mainboard]; } else { return ['status' => 0]; diff --git a/modules-available/statistics/pages/summary.inc.php b/modules-available/statistics/pages/summary.inc.php index 8b476f36..d0538b38 100644 --- a/modules-available/statistics/pages/summary.inc.php +++ b/modules-available/statistics/pages/summary.inc.php @@ -43,10 +43,7 @@ class SubPage Render::closeTag('div'); } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showSummary(StatisticsFilterSet $filterSet) + private static function showSummary(StatisticsFilterSet $filterSet): void { $filterSet->makeFragments($where, $join, $args); $known = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE $where", $args); @@ -66,6 +63,10 @@ class SubPage 'badhdd' => $hdd['val'], ]; // Graph + $labels = []; + $points1 = []; + $points2 = []; + $lectures = []; // Get locations if ($filterSet->suitableForUsageGraph()) { $locFilter = $filterSet->hasFilter('LocationStatisticsFilter'); @@ -89,10 +90,6 @@ class SubPage $cutoff = time() - 2 * 86400; $res = Database::simpleQuery("SELECT dateline, data FROM statistic WHERE typeid = '~stats' AND dateline > $cutoff ORDER BY dateline DESC"); - $labels = []; - $points1 = []; - $points2 = []; - $lectures = []; // Get max from 4 consecutive values, which should be 4*5 = 20m $sum = 0; foreach ($res as $row) { @@ -143,10 +140,7 @@ class SubPage Render::addTemplate('summary', $data); } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showSystemModels($filterSet) + private static function showSystemModels(StatisticsFilterSet $filterSet): void { $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery('SELECT systemmodel, Round(AVG(realcores)) AS cores, Count(*) AS `count` FROM machine m' @@ -186,10 +180,7 @@ class SubPage return $value; } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showMemory($filterSet) + private static function showMemory(StatisticsFilterSet $filterSet): void { $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery("SELECT mbram, Count(*) AS `count` FROM machine m $join @@ -221,10 +212,7 @@ class SubPage Render::addTemplate('memory', $data); } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showKvmState($filterSet) + private static function showKvmState(StatisticsFilterSet $filterSet): void { $filterSet->makeFragments($where, $join, $args); $colors = ['UNKNOWN' => '#666', 'UNSUPPORTED' => '#ea5', 'DISABLED' => '#e55', 'ENABLED' => '#6d6']; @@ -243,10 +231,7 @@ class SubPage Render::addTemplate('kvmstate', array('rows' => $lines, 'json' => json_encode($json))); } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showId44($filterSet) + private static function showId44(StatisticsFilterSet $filterSet): void { $filterSet->makeFragments($where, $join, $args); $res = Database::simpleQuery("SELECT id44mb, Count(*) AS `count` FROM machine m $join WHERE $where GROUP BY id44mb", $args); @@ -283,10 +268,7 @@ class SubPage Render::addTemplate('id44', $data); } - /** - * @param \StatisticsFilterSet $filterSet - */ - private static function showLatestMachines(StatisticsFilterSet $filterSet) + private static function showLatestMachines(StatisticsFilterSet $filterSet): void { $filterSet->makeFragments($where, $join, $args); $args['cutoff'] = ceil(time() / 3600) * 3600 - 86400 * 10; @@ -323,7 +305,7 @@ class SubPage - private static function capChart(&$json, &$rows, $cutoff, $minSlice = 0.015) + private static function capChart(array &$json, array &$rows, float $cutoff, float $minSlice = 0.015): void { $total = 0; foreach ($json as $entry) { @@ -358,9 +340,8 @@ class SubPage /** * @param array $json decoded json ~stats data * @param ?int[] $locations - * @param ?string $op */ - private static function mangleStatsJson(array $json, $locations, $op): array + private static function mangleStatsJson(array $json, ?array $locations, ?string $op): array { // Total, On, InUse, Lectures $retval = [0, 0, 0, 0]; -- cgit v1.2.3-55-g7522