Skip to content

Commit c3ef857

Browse files
committed
Use null coalescing operator for cleaner code in fill_blanks and question classes
1 parent 1aaa53d commit c3ef857

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

main/exercise/fill_blanks.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,13 +1238,13 @@ public static function getHtmlDisplayForAnswer(
12381238
continue;
12391239
}
12401240
}
1241-
$result .= isset($listStudentAnswerInfo['common_words'][$i]) ? $listStudentAnswerInfo['common_words'][$i] : '';
1242-
$studentLabel = isset($listStudentAnswerInfo['student_answer'][$i]) ? $listStudentAnswerInfo['student_answer'][$i] : '';
1241+
$result .= $listStudentAnswerInfo['common_words'][$i] ?? '';
1242+
$studentLabel = $listStudentAnswerInfo['student_answer'][$i] ?? '';
12431243
$result .= $studentLabel;
12441244
}
12451245

12461246
// the last common word (should be </p>)
1247-
$result .= isset($listStudentAnswerInfo['common_words'][$i]) ? $listStudentAnswerInfo['common_words'][$i] : '';
1247+
$result .= $listStudentAnswerInfo['common_words'][$i] ?? '';
12481248

12491249
return $result;
12501250
}

main/exercise/question.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ public function return_header(Exercise $exercise, $counter = null, $score = [])
22552255
case ORAL_EXPRESSION:
22562256
case ANSWER_IN_OFFICE_DOC:
22572257
case ANNOTATION:
2258-
$score['revised'] = isset($score['revised']) ? $score['revised'] : false;
2258+
$score['revised'] = $score['revised'] ?? false;
22592259
if ($score['revised'] == true) {
22602260
$scoreLabel = get_lang('Revised');
22612261
$class = '';
@@ -2304,8 +2304,8 @@ public function return_header(Exercise $exercise, $counter = null, $score = [])
23042304
}
23052305

23062306
$scoreCurrent = [
2307-
'used' => isset($score['score']) ? $score['score'] : '',
2308-
'missing' => isset($score['weight']) ? $score['weight'] : '',
2307+
'used' => $score['score'] ?? '',
2308+
'missing' => $score['weight'] ?? '',
23092309
];
23102310

23112311
// Check whether we need to hide the question ID

main/inc/ajax/exercise.ajax.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,23 +489,22 @@
489489
}
490490

491491
// "all" or "simple" strings means that there's one or all questions exercise type
492-
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
492+
$type = $_REQUEST['type'] ?? null;
493493

494494
// Questions choices.
495-
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : [];
495+
$choice = $_REQUEST['choice'] ?? [];
496496

497497
// certainty degree choice
498-
$choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty']) ? $_REQUEST['choiceDegreeCertainty'] : [];
498+
$choiceDegreeCertainty = $_REQUEST['choiceDegreeCertainty'] ?? [];
499499

500500
// Hot spot coordinates from all questions.
501-
$hot_spot_coordinates = isset($_REQUEST['hotspot']) ? $_REQUEST['hotspot'] : [];
501+
$hot_spot_coordinates = $_REQUEST['hotspot'] ?? [];
502502

503503
// the filenames in upload answer type
504-
$uploadAnswerFileNames = isset($_REQUEST['uploadChoice']) ? $_REQUEST['uploadChoice'] : [];
504+
$uploadAnswerFileNames = $_REQUEST['uploadChoice'] ?? [];
505505

506506
// There is a reminder?
507-
$remind_list = isset($_REQUEST['remind_list']) && !empty($_REQUEST['remind_list'])
508-
? array_keys($_REQUEST['remind_list']) : [];
507+
$remind_list = !empty($_REQUEST['remind_list']) ? array_keys($_REQUEST['remind_list']) : [];
509508

510509
// Needed in manage_answer.
511510
$learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
@@ -662,7 +661,7 @@
662661
if ($type === 'simple' && $question_id != $my_question_id) {
663662
continue;
664663
}
665-
$my_choice = isset($choice[$my_question_id]) ? $choice[$my_question_id] : null;
664+
$my_choice = $choice[$my_question_id] ?? null;
666665
$objQuestionTmp = Question::read($my_question_id, $objExercise->course);
667666
$myChoiceDegreeCertainty = null;
668667
if ($objQuestionTmp->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
@@ -700,8 +699,7 @@
700699

701700
// This variable came from exercise_submit_modal.php.
702701
$hotspot_delineation_result = null;
703-
if (isset($_SESSION['hotspot_delineation_result']) &&
704-
isset($_SESSION['hotspot_delineation_result'][$objExercise->selectId()])
702+
if (isset($_SESSION['hotspot_delineation_result'][$objExercise->selectId()])
705703
) {
706704
$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$my_question_id];
707705
}

0 commit comments

Comments
 (0)