diff options
Diffstat (limited to 'modules-available/locations/inc/locationutil.inc.php')
-rw-r--r-- | modules-available/locations/inc/locationutil.inc.php | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/modules-available/locations/inc/locationutil.inc.php b/modules-available/locations/inc/locationutil.inc.php index 708cc8a2..91117445 100644 --- a/modules-available/locations/inc/locationutil.inc.php +++ b/modules-available/locations/inc/locationutil.inc.php @@ -48,7 +48,7 @@ class LocationUtil if ($overlapOther) { $overlapOther = array(); foreach ($other as $entry) { - if (!isset($locs[$entry['lid1']]) || !isset($locs[$entry['lid2']])) + if (!isset($locs[$entry['lid1']]) && !isset($locs[$entry['lid2']])) continue; if (in_array($entry['lid1'], $locs[$entry['lid2']]['parents']) || in_array($entry['lid2'], $locs[$entry['lid1']]['parents'])) continue; @@ -70,12 +70,9 @@ class LocationUtil * grouped by the location the client was assigned to via roomplanner. * Otherwise, just return an assoc array with the requested locationid, name * and a list of all clients that are wrongfully assigned to that room. - * @param int $locationId - * @return array */ - public static function getMachinesWithLocationMismatch($locationId = 0, $checkPerms = false) + public static function getMachinesWithLocationMismatch(int $locationId = 0, bool $checkPerms = false): array { - $locationId = (int)$locationId; if ($checkPerms) { if ($locationId !== 0) { // Query details for specific location -- use assert and fake array @@ -124,7 +121,7 @@ class LocationUtil $res = Database::simpleQuery($query, $params); $return = []; $locs = false; - while ($row = $res->fetch(PDO::FETCH_ASSOC)) { + foreach ($res as $row) { if (Location::isFixedLocationValid($row['fixedlocationid'], $row['subnetlocationid'])) continue; $lid = (int)$row['fixedlocationid']; @@ -162,19 +159,17 @@ class LocationUtil } if (empty($return)) return $return; - if ($locationId === 0) { + if ($locationId === 0) return array_values($return); - } else { - return $return[$locationId]; - } + return $return[$locationId]; } - private static function overlap($net1, $net2) + private static function overlap(array $net1, array $net2): bool { return ($net1['startaddr'] <= $net2['endaddr'] && $net1['endaddr'] >= $net2['startaddr']); } - public static function rangeToLongVerbose($start, $end) + public static function rangeToLongVerbose(string $start, string $end): ?array { $result = self::rangeToLong($start, $end); list($startLong, $endLong) = $result; @@ -185,24 +180,19 @@ class LocationUtil Message::addWarning('main.value-invalid', 'end addr', $start); } if ($startLong === false || $endLong === false) - return false; + return null; if ($startLong > $endLong) { Message::addWarning('main.value-invalid', 'range', $start . ' - ' . $end); - return false; + return null; } return $result; } - public static function rangeToLong($start, $end) + /** @return array{0: int, 1: int} */ + public static function rangeToLong(string $start, string $end): array { $startLong = ip2long($start); $endLong = ip2long($end); - if ($startLong !== false) { - $startLong = sprintf("%u", $startLong); - } - if ($endLong !== false) { - $endLong = sprintf("%u", $endLong); - } return array($startLong, $endLong); } |