diff options
author | Simon Rettberg | 2023-11-14 14:47:55 +0100 |
---|---|---|
committer | Simon Rettberg | 2023-11-14 14:47:55 +0100 |
commit | 06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch) | |
tree | 7e5493b102074672d8cfd8fe1a61e49f080edbe8 /modules-available/statistics_reporting/inc | |
parent | Update phpstorm config (diff) | |
download | slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.gz slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.tar.xz slx-admin-06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0.zip |
Add function param/return types, fix a lot more phpstorm complaints
Diffstat (limited to 'modules-available/statistics_reporting/inc')
3 files changed, 28 insertions, 30 deletions
diff --git a/modules-available/statistics_reporting/inc/getdata.inc.php b/modules-available/statistics_reporting/inc/getdata.inc.php index 90af0c58..75db119d 100644 --- a/modules-available/statistics_reporting/inc/getdata.inc.php +++ b/modules-available/statistics_reporting/inc/getdata.inc.php @@ -24,7 +24,7 @@ class GetData return $carry . sprintf("%04d", $item); }) . sprintf("%04d", $entry['locationid']); } else { - $entry['locationname'] = Dictionary::translate('notAssigned', true); + $entry['locationname'] = Dictionary::translate('notAssigned'); } if ($anonymize) { unset($entry['locationid']); @@ -56,7 +56,8 @@ class GetData } // total - public static function total($flags = 0) { + public static function total(int $flags = 0): array + { $printable = 0 !== ($flags & GETDATA_PRINTABLE); // total time online, average time online, total number of logins $data = Queries::getOverallStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); @@ -70,7 +71,8 @@ class GetData } // per location - public static function perLocation($flags = 0) { + public static function perLocation(int $flags = 0): array + { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $printable = 0 !== ($flags & GETDATA_PRINTABLE); $data = Queries::getLocationStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); @@ -85,7 +87,8 @@ class GetData } // per client - public static function perClient($flags = 0, $new = false) { + public static function perClient(int $flags = 0): array + { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $printable = 0 !== ($flags & GETDATA_PRINTABLE); $data = Queries::getClientStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); @@ -101,7 +104,8 @@ class GetData } // per user - public static function perUser($flags = 0) { + public static function perUser(int $flags = 0): array + { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getUserStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); @@ -116,7 +120,8 @@ class GetData // per vm - public static function perVM($flags = 0) { + public static function perVM(int $flags = 0): array + { $anonymize = 0 !== ($flags & GETDATA_ANONYMOUS); $res = Queries::getVMStatistics(self::$from, self::$to, self::$lowerTimeBound, self::$upperTimeBound); $data = array(); @@ -130,7 +135,7 @@ class GetData return $data; } - private static function nullToZero(&$row) + private static function nullToZero(array &$row): void { foreach ($row as &$field) { if (is_null($field)) { @@ -140,7 +145,7 @@ class GetData } // Format $seconds into ".d .h .m .s" format (day, hour, minute, second) - private static function formatSeconds($seconds) + private static function formatSeconds(int $seconds): string { return sprintf('%dd, %02d:%02d:%02d', $seconds / (3600*24), ($seconds % (3600*24)) / 3600, ($seconds%3600) / 60, $seconds%60); } diff --git a/modules-available/statistics_reporting/inc/queries.inc.php b/modules-available/statistics_reporting/inc/queries.inc.php index 2465e557..bafe80bc 100644 --- a/modules-available/statistics_reporting/inc/queries.inc.php +++ b/modules-available/statistics_reporting/inc/queries.inc.php @@ -13,7 +13,7 @@ class Queries } } - public static function getClientStatistics(int $from, int $to, $lowerTimeBound = 0, $upperTimeBound = 24) + public static function getClientStatistics(int $from, int $to, int $lowerTimeBound = 0, int $upperTimeBound = 24): array { $fromCutoff = $from - 86400 * 30; $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, @@ -28,7 +28,7 @@ class Queries return $machines; } - public static function getLocationStatistics(int $from, int $to, $lowerTimeBound = 0, $upperTimeBound = 24) + public static function getLocationStatistics(int $from, int $to, int $lowerTimeBound = 0, int $upperTimeBound = 24): array { $fromCutoff = $from - 86400 * 30; $res = Database::simpleQuery("SELECT m.machineuuid, m.hostname, m.clientip, @@ -37,7 +37,7 @@ class Queries $machines = self::getStats3($res, $from, $to, $lowerTimeBound, $upperTimeBound); $locations = []; $keys = ['locationid', 'totalTime', 'totalOffTime', 'totalSessionTime', 'totalStandbyTime', 'totalIdleTime', 'totalIdleTime', 'longSessions', 'shortSessions', 'sessions']; - while ($machine = array_pop($machines)) { + while (($machine = array_pop($machines)) !== null) { if (!isset($locations[$machine['locationid']])) { self::keepKeys($machine, $keys); $locations[$machine['locationid']] = $machine; @@ -69,7 +69,7 @@ class Queries $machines = self::getStats3($res, $from, $to, $lowerTimeBound, $upperTimeBound); $total = false; $keys = ['totalTime', 'totalOffTime', 'totalSessionTime', 'totalStandbyTime', 'totalIdleTime', 'totalIdleTime', 'longSessions', 'shortSessions', 'sessions']; - while ($machine = array_pop($machines)) { + while (($machine = array_pop($machines)) !== null) { if ($total === false) { self::keepKeys($machine, $keys); $total = $machine; @@ -89,15 +89,7 @@ class Queries return $total; } - /** - * @param \PDOStatement $res - * @param int $from - * @param int $to - * @param int $lowerTimeBound - * @param int $upperTimeBound - * @return array - */ - private static function getStats3($res, $from, $to, $lowerTimeBound, $upperTimeBound) + private static function getStats3(PDOStatement $res, int $from, int $to, int $lowerTimeBound, int $upperTimeBound): array { //$debug = false; if ($lowerTimeBound === 0 && $upperTimeBound === 24 || $upperTimeBound <= $lowerTimeBound) { @@ -228,8 +220,8 @@ class Queries } */ $machine[$row['typeid']] += self::timeDiff($start, $end, $bounds); - $sh = date('G', $start); } + $sh = date('G', $start); if ($row['typeid'] === 'totalSessionTime' && ($bounds === false || ($sh >= $bounds[0] && $sh < $bounds[1]))) { if ($row['data'] >= 60) { $machine['longSessions'] += 1; @@ -307,17 +299,18 @@ class Queries /** * Get median of array. - * @param int[] list of values + * @param int[] $array list of values * @return int The median */ - private static function calcMedian($array) { + private static function calcMedian(array $array): int + { if (empty($array)) return 0; sort($array, SORT_NUMERIC); $count = count($array); //total numbers in array $middleval = (int)floor(($count-1) / 2); // find the middle value, or the lowest middle value if($count % 2 === 1) { // odd number, middle is the median - return (int)$array[$middleval]; + return $array[$middleval]; } // even number, calculate avg of 2 medians $low = $array[$middleval]; @@ -343,7 +336,7 @@ class Queries GROUP BY data"); } - public static function getDozmodStats(int $from, int $to) + public static function getDozmodStats(int $from, int $to): array { if (Module::get('dozmod') === false) return ['disabled' => true]; @@ -364,7 +357,7 @@ class Queries return $return; } - public static function getExamStats(int $from, int $to) + public static function getExamStats(int $from, int $to): array { if (Module::get('exams') === false) return ['disabled' => true]; @@ -395,7 +388,7 @@ class Queries return $return; } - public static function getAggregatedMachineStats($from) + public static function getAggregatedMachineStats(int $from): array { $return = array(); $return['location'] = Database::queryAll("SELECT MD5(CONCAT(locationid, :salt)) AS `location`, Count(*) AS `count` @@ -436,7 +429,7 @@ class Queries * @param int $to end timestamp * @return int count of user active in timespan */ - public static function getUniqueUserCount($from, $to) + public static function getUniqueUserCount(int $from, int $to): int { $res = Database::queryFirst("SELECT Count(DISTINCT username) as `total` FROM statistic diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 7227259a..ebd31046 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -109,7 +109,7 @@ class RemoteReport $uptime = file_get_contents('/proc/uptime'); $memInfo = file_get_contents('/proc/meminfo'); $osInfo = parse_ini_file('/etc/os-release'); - preg_match_all('/\b(\w+):\s+(\d+)\s/s', $memInfo, $out, PREG_SET_ORDER); + preg_match_all('/\b(\w+):\s+(\d+)\s/', $memInfo, $out, PREG_SET_ORDER); $mem = array(); foreach ($out as $e) { $mem[$e[1]] = $e[2]; |