From 06bff0b9b84d47c43f9bc8aff06a29d85ebb7ed0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 Nov 2023 14:47:55 +0100 Subject: Add function param/return types, fix a lot more phpstorm complaints --- modules-available/exams/baseconfig/getconfig.inc.php | 13 +++++++------ modules-available/exams/inc/exams.inc.php | 9 +++------ modules-available/exams/page.inc.php | 20 +++++++++++++------- 3 files changed, 23 insertions(+), 19 deletions(-) (limited to 'modules-available/exams') diff --git a/modules-available/exams/baseconfig/getconfig.inc.php b/modules-available/exams/baseconfig/getconfig.inc.php index 120bdbff..748149ad 100644 --- a/modules-available/exams/baseconfig/getconfig.inc.php +++ b/modules-available/exams/baseconfig/getconfig.inc.php @@ -1,14 +1,17 @@ $machineUuid), true); + array('uuid' => $uuid), true); if (is_array($res)) return; // Check if exam mode should apply $locations = ConfigHolder::get('SLX_LOCATIONS'); - if ($locations === false) { + if ($locations === null) { $locationIds = []; } else { $locationIds = explode(' ', $locations); @@ -26,6 +29,4 @@ $foofoo = function($machineUuid) { // No saver ConfigHolder::add('SLX_SCREEN_SAVER_TIMEOUT', '0', 1000); } -}; - -$foofoo($uuid); \ No newline at end of file +} \ No newline at end of file diff --git a/modules-available/exams/inc/exams.inc.php b/modules-available/exams/inc/exams.inc.php index da4dec85..86dc6d89 100644 --- a/modules-available/exams/inc/exams.inc.php +++ b/modules-available/exams/inc/exams.inc.php @@ -4,14 +4,11 @@ class Exams { /** - * @param int[] of location ids. must bot be an associative array. - * @return: bool true iff for any of the given location ids an exam is scheduled. + * @param int[] $locationIds of location ids. must be an associative array. + * @return bool true iff for any of the given location ids an exam is scheduled. **/ - public static function isInExamMode($locationIds, &$lectureId = false, &$autoLogin = false) + public static function isInExamMode(array $locationIds, &$lectureId = false, &$autoLogin = false): bool { - if (!is_array($locationIds)) { - $locationIds = array($locationIds); - } if (empty($locationIds)) { $locationIds[] = 0; } diff --git a/modules-available/exams/page.inc.php b/modules-available/exams/page.inc.php index 458ae5b1..d229b883 100644 --- a/modules-available/exams/page.inc.php +++ b/modules-available/exams/page.inc.php @@ -103,7 +103,7 @@ class Page_Exams extends Page } // returns true if user is allowed to edit the exam - protected function userCanEditExam($examid = NULL) + protected function userCanEditExam(string $examid = NULL): bool { if (in_array(0, $this->userEditLocations)) // Trivial case -- don't query if global perms return true; @@ -118,9 +118,12 @@ class Page_Exams extends Page return true; } - // checks if user is allowed to save an exam with all the locations - // needs information if it's add (second para = true) or edit (second para = false) - protected function userCanEditLocation($locationids) { + /** + * checks if user is allowed to save an exam with all the locations + * needs information if it's add (second para = true) or edit (second para = false) + */ + protected function userCanEditLocation(array $locationids): bool + { return empty(array_diff($locationids, $this->userEditLocations)); } @@ -213,7 +216,10 @@ class Page_Exams extends Page return json_encode($out); } - protected function makeExamsForTemplate() + /** + * @return array{exams: array, decollapse: bool} + */ + protected function makeExamsForTemplate(): array { $out = []; $now = time(); @@ -248,7 +254,7 @@ class Page_Exams extends Page return ['exams' => $out, 'decollapse' => $hasCollapsed]; } - protected function makeLectureExamList() + protected function makeLectureExamList(): array { $out = []; $now = time(); @@ -288,7 +294,7 @@ class Page_Exams extends Page ] + $source; } - private function isDateSane($time) + private function isDateSane(int $time): bool { return ($time >= strtotime('-10 years') && $time <= strtotime('+10 years')); } -- cgit v1.2.3-55-g7522