summaryrefslogtreecommitdiffstats
path: root/modules-available/systemstatus
diff options
context:
space:
mode:
authorSimon Rettberg2023-11-14 14:47:55 +0100
committerSimon Rettberg2023-11-14 14:47:55 +0100
commit06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 (patch)
tree7e5493b102074672d8cfd8fe1a61e49f080edbe8 /modules-available/systemstatus
parentUpdate phpstorm config (diff)
downloadslx-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/systemstatus')
-rw-r--r--modules-available/systemstatus/inc/systemstatus.inc.php2
-rw-r--r--modules-available/systemstatus/page.inc.php27
2 files changed, 14 insertions, 15 deletions
diff --git a/modules-available/systemstatus/inc/systemstatus.inc.php b/modules-available/systemstatus/inc/systemstatus.inc.php
index 7f3e5d42..4f87fa4e 100644
--- a/modules-available/systemstatus/inc/systemstatus.inc.php
+++ b/modules-available/systemstatus/inc/systemstatus.inc.php
@@ -13,7 +13,7 @@ class SystemStatus
* @param string|false $wantedSource What should be mounted as vmstore (false if nothing configured)
* @return bool false if querying fs data from taskmanager failed
*/
- public static function diskStat(&$systemUsage, &$storeUsage, &$currentSource = false, &$wantedSource = false)
+ public static function diskStat(&$systemUsage, &$storeUsage, &$currentSource = false, &$wantedSource = false): bool
{
$task = Taskmanager::submit('DiskStat');
if ($task === false)
diff --git a/modules-available/systemstatus/page.inc.php b/modules-available/systemstatus/page.inc.php
index c87dabda..dbad2871 100644
--- a/modules-available/systemstatus/page.inc.php
+++ b/modules-available/systemstatus/page.inc.php
@@ -92,7 +92,7 @@ class Page_SystemStatus extends Page
foreach ($tabs as $tab) {
$data['tabs'][] = array(
'type' => $tab,
- 'name' => Dictionary::translate('tab_' . $tab, true),
+ 'name' => Dictionary::translate('tab_' . $tab),
'enabled' => User::hasPermission('tab.' . $tab),
'important' => $tab === 'ListUpgradable' && SystemStatus::getAptLastDbUpdateTime() + 864000 < time(),
);
@@ -117,7 +117,8 @@ class Page_SystemStatus extends Page
$this->$action();
Message::renderList();
} else {
- echo "Action $action not known in " . get_class();
+ // get_class() !== get_class($this)
+ echo "Action $action not known in " . get_class($this);
}
}
@@ -212,16 +213,17 @@ class Page_SystemStatus extends Page
'addresses' => $task['data']['addresses']
));
}
-
- private function sysInfo()
+
+ private function sysInfo(): array
{
$data = array();
$memInfo = file_get_contents('/proc/meminfo');
$stat = file_get_contents('/proc/stat');
- 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);
foreach ($out as $e) {
$data[$e[1]] = $e[2];
}
+ /** @var array{user: numeric, nice: numeric, system: numeric, idle: numeric, iowait: numeric, irq: numeric, softirq: numeric} $out */
if (preg_match('/\bcpu\s+(?<user>\d+)\s+(?<nice>\d+)\s+(?<system>\d+)\s+(?<idle>\d+)\s+(?<iowait>\d+)\s+(?<irq>\d+)\s+(?<softirq>\d+)(\s|$)/', $stat, $out)) {
$data['CpuTotal'] = $out['user'] + $out['nice'] + $out['system'] + $out['idle'] + $out['iowait'] + $out['irq'] + $out['softirq'];
$data['CpuIdle'] = $out['idle'] + $out['iowait'];
@@ -438,7 +440,7 @@ class Page_SystemStatus extends Page
$output = [];
foreach ($ids as $id) {
$module = ConfigModule::get($id);
- if ($module === false) {
+ if ($module === null) {
$name = "#$id";
} else {
$name = $module->title();
@@ -462,10 +464,7 @@ class Page_SystemStatus extends Page
return;
$status = Taskmanager::waitComplete($taskId, 3500);
- if (isset($status['data']['messages']))
- $data = $status['data']['messages'];
- else
- $data = 'Taskmanager error';
+ $data = $status['data']['messages'] ?? 'Taskmanager error';
echo '<pre>', htmlspecialchars($data, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '</pre>';
}
@@ -478,14 +477,14 @@ class Page_SystemStatus extends Page
return;
$status = Taskmanager::waitComplete($taskId, 3500);
- if (isset($status['data']['messages']))
- $data = $status['data']['messages'];
- else
- $data = 'Taskmanager error';
+ $data = $status['data']['messages'] ?? 'Taskmanager error';
echo '<pre>', htmlspecialchars($data, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'), '</pre>';
}
+ /**
+ * @return array{percent: numeric, size: string, free: string, color: string, filesystem: string}
+ */
private function convertDiskStat(array $stat, int $minFreeMb): array
{
return [