From c7acfdce3a8804cdcbeec453cecc879e0b2215d9 Mon Sep 17 00:00:00 2001 From: Jonathan Champ Date: Fri, 21 Jul 2023 13:29:52 -0400 Subject: [PATCH] phpcs: small cleanups --- classes/task/get_meeting_reports.php | 22 +++++++-------- settings.php | 26 ++++++++++++----- tests/get_meeting_reports_test.php | 42 +++++++++++++++------------- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/classes/task/get_meeting_reports.php b/classes/task/get_meeting_reports.php index 9cdd1bbf..02068d6f 100644 --- a/classes/task/get_meeting_reports.php +++ b/classes/task/get_meeting_reports.php @@ -261,7 +261,7 @@ public function format_participant($participant, $detailsid, $names, $emails) { } } - if ($participant->user_email == '') { + if ($participant->user_email === '') { if (!empty($moodleuserid)) { $participant->user_email = $DB->get_field('user', 'email', ['id' => $moodleuserid]); } else { @@ -269,7 +269,7 @@ public function format_participant($participant, $detailsid, $names, $emails) { } } - if ($participant->id == '') { + if ($participant->id === '') { $participant->id = null; } @@ -469,7 +469,7 @@ public function debugmsg($msg) { * @return boolean */ public function process_meeting_reports($meeting) { - global $DB, $CFG; + global $DB; $this->debugmsg(sprintf('Processing meeting %s|%s that occurred at %s', $meeting->meeting_id, $meeting->uuid, $meeting->start_time)); @@ -540,7 +540,7 @@ public function process_meeting_reports($meeting) { 'detailsid' => $participant['detailsid'], 'zoomuserid' => $participant['zoomuserid'], 'join_time' => $participant['join_time'], - 'leave_time' => $participant['leave_time'] + 'leave_time' => $participant['leave_time'], ]; // Check if the record already exists. @@ -631,7 +631,7 @@ public function grading_participant_upon_duration($zoomrecord, $detailsid) { // Check if there is old duration stored for this user. if (!empty($durations[$userid])) { - $old = new \stdClass; + $old = new \stdClass(); $old->duration = $durations[$userid]; $old->join_time = $join[$userid]; $old->leave_time = $leave[$userid]; @@ -708,7 +708,6 @@ public function grading_participant_upon_duration($zoomrecord, $detailsid) { } else { $notenrolled[$userid] = fullname(\core_user::get_user($userid)); } - } else { // This means that this user was not identified. // Provide information about participants that need to be graded manually. @@ -808,7 +807,7 @@ public function notify_teachers($data) { $needgradenumber = count($data['needgrade']); // List of users need grading. $needstring = get_string('grading_needgrade', 'mod_zoom'); - $needgrade = (!empty($data['needgrade'])) ? $needstring.implode('
', $data['needgrade'])."\n" : ''; + $needgrade = (!empty($data['needgrade'])) ? $needstring . implode('
', $data['needgrade']) . "\n" : ''; $zoomid = $data['zoomid']; $itemid = $data['itemid']; @@ -886,7 +885,7 @@ public function notify_teachers($data) { $message->contexturl = $gurl; // This link redirect the teacher to the page of item's grades. $message->contexturlname = get_string('gradinglink', 'mod_zoom'); // Email content. - $content = array('*' => array('header' => $message->subject, 'footer' => '')); + $content = ['*' => ['header' => $message->subject, 'footer' => '']]; $message->set_additional_content('email', $content); $messageids = []; if (!empty($teachers)) { @@ -980,9 +979,10 @@ public function get_users_clicked_join($zoomrecord) { $userids = []; foreach ($events as $event) { - if ($event->other['meetingid'] == $zoomrecord->meeting_id && - !in_array($event->userid, $userids)) { - + if ( + $event->other['meetingid'] === $zoomrecord->meeting_id && + !in_array($event->userid, $userids, true) + ) { $userids[] = $event->userid; } } diff --git a/settings.php b/settings.php index 65d141db..3df7e9bf 100644 --- a/settings.php +++ b/settings.php @@ -175,8 +175,13 @@ 'idfullname' => get_string('displayidfullname', 'mod_zoom'), 'id' => get_string('displayid', 'mod_zoom'), ]; - $settings->add(new admin_setting_configselect('zoom/unamedisplay', get_string('unamedisplay', 'mod_zoom'), - get_string('unamedisplay_help', 'mod_zoom'), 'fullname', $options)); + $settings->add(new admin_setting_configselect( + 'zoom/unamedisplay', + get_string('unamedisplay', 'mod_zoom'), + get_string('unamedisplay_help', 'mod_zoom'), + 'fullname', + $options + )); // Supplementary features settings. $settings->add(new admin_setting_heading('zoom/supplementaryfeaturessettings', @@ -436,9 +441,11 @@ } // Adding options for grading methods. - $settings->add(new admin_setting_heading('zoom/gradingmethod', - get_string('gradingmethod_heading', 'mod_zoom'), - get_string('gradingmethod_heading_help', 'mod_zoom'))); + $settings->add(new admin_setting_heading( + 'zoom/gradingmethod', + get_string('gradingmethod_heading', 'mod_zoom'), + get_string('gradingmethod_heading_help', 'mod_zoom') + )); // Grading method upon entry: the user gets the full score when clicking to join the session through Moodle. // Grading method upon period: the user is graded based on how long they attended the actual session. @@ -446,6 +453,11 @@ 'entry' => get_string('gradingentry', 'mod_zoom'), 'period' => get_string('gradingperiod', 'mod_zoom'), ]; - $settings->add(new admin_setting_configselect('zoom/gradingmethod', get_string('gradingmethod', 'mod_zoom'), - get_string('gradingmethod_help', 'mod_zoom'), 'entry', $options)); + $settings->add(new admin_setting_configselect( + 'zoom/gradingmethod', + get_string('gradingmethod', 'mod_zoom'), + get_string('gradingmethod_help', 'mod_zoom'), + 'entry', + $options + )); } diff --git a/tests/get_meeting_reports_test.php b/tests/get_meeting_reports_test.php index a565701c..2c0b1105 100644 --- a/tests/get_meeting_reports_test.php +++ b/tests/get_meeting_reports_test.php @@ -441,7 +441,7 @@ public function test_grading_method() { $context = \context_course::instance($course->id); $graders = get_users_by_capability($context, 'moodle/grade:edit'); $this->assertEquals(1, count($graders)); - $firstkey = array_key_first($graders); + $firstkey = key($graders); $this->assertEquals($graders[$firstkey]->id, $teacher->id); // Now fake the meeting details. $meeting = new stdClass(); @@ -505,7 +505,7 @@ public function test_grading_method() { foreach ($users as $user) { $this->getDataGenerator()->enrol_user($user->id, $course->id); } - list($names, $emails) = $this->meetingtask->get_enrollments($course->id); + [$names, $emails] = $this->meetingtask->get_enrollments($course->id); // Create a participant with 5 min overlap. // Total time 35 min, total grade 17.5 . @@ -516,7 +516,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:05:00Z', 'leave_time' => '2023-05-01T15:35:00Z', - 'duration' => 30 * 60 + 'duration' => 30 * 60, ]; $participants[1] = (object)$this->meetingtask->format_participant($rawparticipants[1], $detailsid, $names, $emails); $rawparticipants[2] = (object)[ @@ -526,7 +526,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:30:00Z', 'leave_time' => '2023-05-01T15:40:00Z', - 'duration' => 10 * 60 + 'duration' => 10 * 60, ]; $participants[2] = (object)$this->meetingtask->format_participant($rawparticipants[2], $detailsid, $names, $emails); $overlap = $this->meetingtask->get_participant_overlap_time($participants[1], $participants[2]); @@ -544,7 +544,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:00:00Z', 'leave_time' => '2023-05-01T16:00:00Z', - 'duration' => 60 * 60 + 'duration' => 60 * 60, ]; $participants[3] = (object)$this->meetingtask->format_participant($rawparticipants[3], $detailsid, $names, $emails); $rawparticipants[4] = (object)[ @@ -554,7 +554,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:30:00Z', 'leave_time' => '2023-05-01T16:00:00Z', - 'duration' => 30 * 60 + 'duration' => 30 * 60, ]; $participants[4] = (object)$this->meetingtask->format_participant($rawparticipants[4], $detailsid, $names, $emails); $overlap = $this->meetingtask->get_participant_overlap_time($participants[3], $participants[4]); @@ -572,7 +572,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:10:00Z', 'leave_time' => '2023-05-01T16:00:00Z', - 'duration' => 50 * 60 + 'duration' => 50 * 60, ]; $participants[5] = (object)$this->meetingtask->format_participant($rawparticipants[5], $detailsid, $names, $emails); $rawparticipants[6] = (object)[ @@ -582,7 +582,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T16:30:00Z', 'leave_time' => '2023-05-01T16:40:00Z', - 'duration' => 10 * 60 + 'duration' => 10 * 60, ]; $participants[6] = (object)$this->meetingtask->format_participant($rawparticipants[6], $detailsid, $names, $emails); @@ -601,7 +601,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:30:00Z', 'leave_time' => '2023-05-01T17:00:00Z', - 'duration' => 90 * 60 + 'duration' => 90 * 60, ]; // Adding a participant at which matching names will fail. @@ -613,7 +613,7 @@ public function test_grading_method() { 'user_email' => '', 'join_time' => '2023-05-01T15:10:00Z', 'leave_time' => '2023-05-01T17:00:00Z', - 'duration' => 110 * 60 + 'duration' => 110 * 60, ]; $this->mockparticipantsdata['someuuid123'] = $rawparticipants; // First mock the webservice object, so we can inject the return values @@ -624,8 +624,10 @@ public function test_grading_method() { $mockwwebservice->method('get_meeting_participants') ->will($this->returnCallback([$this, 'mock_get_meeting_participants'])); - $this->assertEquals($this->mockparticipantsdata['someuuid123'], - $mockwwebservice->get_meeting_participants('someuuid123', false)); + $this->assertEquals( + $this->mockparticipantsdata['someuuid123'], + $mockwwebservice->get_meeting_participants('someuuid123', false) + ); // Now let's test the grads. set_config('gradingmethod', 'period', 'zoom'); @@ -672,13 +674,13 @@ public function test_grading_method() { // Check the content of the message. // Grading item url. $gurl = new \moodle_url( - '/grade/report/singleview/index.php', - [ - 'id' => $course->id, - 'item' => 'grade', - 'itemid' => $gradelistitems[0]->id, - ] - ); + '/grade/report/singleview/index.php', + [ + 'id' => $course->id, + 'item' => 'grade', + 'itemid' => $gradelistitems[0]->id, + ] + ); $gradeurl = \html_writer::link($gurl, get_string('gradinglink', 'mod_zoom')); // Zoom instance url. @@ -687,7 +689,7 @@ public function test_grading_method() { // The user need grading. $needgradestr = get_string('grading_needgrade', 'mod_zoom'); $needgrade[] = '(Name: Farouk, grade: 55)'; - $needgrade = $needgradestr.implode('
', $needgrade)."\n"; + $needgrade = $needgradestr . implode('
', $needgrade) . "\n"; $a = (object)[ 'name' => $zoomrecord->name,