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/dnbd3/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/dnbd3/inc')
-rw-r--r-- | modules-available/dnbd3/inc/dnbd3rpc.inc.php | 17 | ||||
-rw-r--r-- | modules-available/dnbd3/inc/dnbd3util.inc.php | 19 |
2 files changed, 14 insertions, 22 deletions
diff --git a/modules-available/dnbd3/inc/dnbd3rpc.inc.php b/modules-available/dnbd3/inc/dnbd3rpc.inc.php index a26ae4fd..f6bbf0ca 100644 --- a/modules-available/dnbd3/inc/dnbd3rpc.inc.php +++ b/modules-available/dnbd3/inc/dnbd3rpc.inc.php @@ -18,17 +18,9 @@ class Dnbd3Rpc { // Special case - local server if ($server === '<self>') { $server = '127.0.0.1:5003'; - } elseif (($out = Dnbd3Util::matchAddress($server))) { - if (isset($out['v4'])) { - $server = $out['v4']; - } else { - $server = '[' . $out['v6'] . ']'; - } - if (isset($out['port'])) { - $server .= $out['port']; - } else { - $server .= ':5003'; - } + } elseif (($out = Dnbd3Util::matchAddress($server)) !== false) { + $server = $out['v4'] ?? '[' . $out['v6'] . ']'; + $server .= $out['port'] ?? ':5003'; } return $server; } @@ -72,7 +64,6 @@ class Dnbd3Rpc { /** * Get statistics for multiple servers at once. * @param string[] $servers - * @return array */ public static function getStatsMulti(array $servers, array $queryOptions = [], int $timeout = 2): array { @@ -91,7 +82,7 @@ class Dnbd3Rpc { $url = 'http://' . self::translateServer($server) . '/query?q=version' . $extra; $res = curl_init($url); if ($res === false) { - error_log("curl_init($url) failed with $res"); + error_log("curl_init($url) failed"); continue; } curl_setopt_array($res, [ diff --git a/modules-available/dnbd3/inc/dnbd3util.inc.php b/modules-available/dnbd3/inc/dnbd3util.inc.php index 90940e8a..47d7a4ea 100644 --- a/modules-available/dnbd3/inc/dnbd3util.inc.php +++ b/modules-available/dnbd3/inc/dnbd3util.inc.php @@ -108,11 +108,9 @@ class Dnbd3Util { /** * A client is booting that has runmode dnbd3 proxy - set config vars accordingly. * - * @param string $machineUuid * @param string $mode always 'proxy' - * @param string $modeData */ - public static function runmodeConfigHook($machineUuid, $mode, $modeData) + public static function runmodeConfigHook(string $machineUuid, string $mode, string $modeData) { $self = Property::getServerIp(); // Get all directly assigned locations @@ -125,7 +123,7 @@ class Dnbd3Util { $assignedLocs[] = $row['locationid']; } $modeData = (array)json_decode($modeData, true) + self::defaultRunmodeConfig(); - if (!empty($assignedLocs) && isset($modeData['firewall']) && $modeData['firewall']) { + if (!empty($assignedLocs) && ($modeData['firewall'] ?? false)) { // Get all sub-locations too $recursiveLocs = $assignedLocs; $locations = Location::getLocationsAssoc(); @@ -215,10 +213,10 @@ class Dnbd3Util { * @param int $end end address * @return string CIDR notation */ - private static function range2Cidr($start, $end) + private static function range2Cidr(int $start, int $end): string { if (PHP_INT_SIZE > 4) { - $bin = decbin((int)$start ^ (int)$end); + $bin = decbin($start ^ $end); } else { $bin = decbin((int)(float)$start ^ (int)(float)$end); } @@ -258,12 +256,15 @@ class Dnbd3Util { $ranges[] = $row; } - public static function defaultRunmodeConfig() + /** + * @return array{bgr: bool, firewall: bool} + */ + public static function defaultRunmodeConfig(): array { - return array( + return [ 'bgr' => true, 'firewall' => false - ); + ]; } public static function matchAddress($server) |