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/roomplanner/inc/room.inc.php | |
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/roomplanner/inc/room.inc.php')
-rw-r--r-- | modules-available/roomplanner/inc/room.inc.php | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/modules-available/roomplanner/inc/room.inc.php b/modules-available/roomplanner/inc/room.inc.php index 1a7a80ae..880cb6d0 100644 --- a/modules-available/roomplanner/inc/room.inc.php +++ b/modules-available/roomplanner/inc/room.inc.php @@ -29,10 +29,10 @@ abstract class Room FROM location_roomplan lr LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid)'); foreach ($ret as $row) { - $row = self::loadSingleRoom($row); - if ($row === false) + $room = self::loadSingleRoom($row); + if ($room === null) continue; - self::$rooms[$row->locationId] = $row; + self::$rooms[$room->locationId] = $room; } foreach (self::$rooms as $room) { $room->sanitize(); @@ -42,14 +42,14 @@ abstract class Room /** * Instantiate ComposedRoom or MachineGroup depending on contents of $row * @param array $row DB row from location_roomplan. - * @return Room|false Room instance, false on error + * @return ?Room Room instance, null on error */ - private static function loadSingleRoom($row) + private static function loadSingleRoom(array $row): ?Room { $locations = Location::getLocationsAssoc(); settype($row['locationid'], 'int'); if (!isset($locations[$row['locationid']])) - return false; + return null; if ($locations[$row['locationid']]['isleaf']) return new SimpleRoom($row); return new ComposedRoom($row, false); @@ -59,7 +59,7 @@ abstract class Room * Get array of all rooms with room plan * @return Room[] */ - public static function getAll() + public static function getAll(): array { self::init(); return self::$rooms; @@ -68,9 +68,9 @@ abstract class Room /** * Get room instance for given location * @param int $locationId room to get - * @return Room|false requested room, false if not configured or not found + * @return ?Room requested room, false if not configured or not found */ - public static function get($locationId) + public static function get(int $locationId): ?Room { if (self::$rooms === null) { $room = Database::queryFirst( @@ -79,8 +79,10 @@ abstract class Room LEFT JOIN machine m ON (lr.tutoruuid = m.machineuuid) WHERE lr.locationid = :lid', ['lid' => $locationId]); if ($room === false) - return false; + return null; $room = self::loadSingleRoom($room); + if ($room === null) + return null; // If it's a leaf room we probably don't need any other rooms, return it if ($room->isLeaf()) return $room; @@ -89,7 +91,7 @@ abstract class Room } if (isset(self::$rooms[$locationId])) return self::$rooms[$locationId]; - return false; + return null; } public function __construct($row) @@ -102,35 +104,34 @@ abstract class Room /** * @return int number of machines in this room */ - abstract public function machineCount(); + abstract public function machineCount(): int; /** * Size of this room, returned by reference. - * @param int $width OUT width of room - * @param int $height OUT height of room + * + * @param int|null $width OUT width of room + * @param int|null $height OUT height of room */ - abstract public function getSize(&$width, &$height); + abstract public function getSize(?int &$width, ?int &$height); /** * Get clients in this room in .ini format for PVS. * Adjusted so the top/left client is at (0|0), which * is further adjustable with $offX and $offY. + * * @param int $i offset for indexing clients * @param int $offX positional X offset for clients * @param int $offY positional Y offset for clients * @return string|false */ - abstract public function getIniClientSection(&$i, $offX = 0, $offY = 0); + abstract public function getIniClientSection(int &$i, int $offX = 0, int $offY = 0); /** * Get clients in this room as array. * Adjusted so the top/left client is at (0|0), which *is further adjustable with $offX and $offY. - * @param int $offX - * @param int $offY - * @return array */ - abstract public function getShiftedArray($offX = 0, $offY = 0); + abstract public function getShiftedArray(int $offX = 0, int $offY = 0): ?array; /** * @return string|false IP address of manager. @@ -145,12 +146,12 @@ abstract class Room /** * @return bool true if this is a simple/leaf room, false for composed rooms. */ - abstract public function isLeaf(); + abstract public function isLeaf(): bool; /** * @return bool should this room be skipped from output? true for empty SimpleRoom or disabled ComposedRoom. */ - abstract public function shouldSkip(); + abstract public function shouldSkip(): bool; /** * Sanitize this room's data. @@ -160,7 +161,7 @@ abstract class Room /** * @return string get room's name. */ - public function locationName() + public function locationName(): string { return $this->locationName; } @@ -168,7 +169,7 @@ abstract class Room /** * @return int get room's id. */ - public function locationId() + public function locationId(): int { return $this->locationId; } |