Skip to content

Commit

Permalink
MDL-63422 general: review core loop / switch / case / continue
Browse files Browse the repository at this point in the history
This commit reviews all continue uses in core happening within a
loop / switch / case hierarchy. This does not cover:

- Changes to libraries. Will be handled in another issue / commit.
- Uses out from loops, will be reviewed by other commit.

The policy followed has been:
- When possible, take rid of the continue.
- When clearly the intention was to jump to next element in loop
  change to continue 2
- When it was not clear, keep old behavior switching to break, no
  matter how weird the behavior may be.
  • Loading branch information
stronk7 committed Oct 30, 2018
1 parent 8b019fb commit bd5fdcf
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 71 deletions.
2 changes: 1 addition & 1 deletion analytics/classes/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ private function format_predictor_predictions($predictorresult) {
// skip it and do nothing with it.
debugging($this->model->id . ' model predictions processor could not process the sample with id ' .
$sampleinfo[0], DEBUG_DEVELOPER);
continue;
continue 2;
case 2:
// Prediction processors that do not return a prediction score will have the maximum prediction
// score.
Expand Down
2 changes: 1 addition & 1 deletion blog/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static function export_user_data(approved_contextlist $contextlist) {

if (empty($entryids)) {
// This should not happen, as the user context should not have been reported then.
continue;
continue 2;
}

list($insql, $inparams) = $DB->get_in_or_equal($entryids, SQL_PARAMS_NAMED);
Expand Down
9 changes: 4 additions & 5 deletions competency/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,14 +500,13 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
foreach ($contextlist as $context) {
switch ($context->contextlevel) {
case CONTEXT_USER:
if ($context->instanceid != $userid) {
if ($context->instanceid == $userid) {
// Only delete the user's information when they requested their context to be deleted. We
// do not take any action on other user's contexts because we don't own the data there.
continue;
static::delete_user_evidence_of_prior_learning($userid);
static::delete_user_plans($userid);
static::delete_user_competencies($userid);
}
static::delete_user_evidence_of_prior_learning($userid);
static::delete_user_plans($userid);
static::delete_user_competencies($userid);
break;

case CONTEXT_COURSE:
Expand Down
4 changes: 2 additions & 2 deletions grade/querylib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function grade_get_course_grades($courseid, $userid_or_ids=null) {

switch ($grade_item->gradetype) {
case GRADE_TYPE_NONE:
continue;
break;

case GRADE_TYPE_VALUE:
$item->scaleid = 0;
Expand Down Expand Up @@ -178,7 +178,7 @@ function grade_get_course_grade($userid, $courseid_or_ids=null) {

switch ($grade_item->gradetype) {
case GRADE_TYPE_NONE:
continue;
break;

case GRADE_TYPE_VALUE:
$item->scaleid = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/gradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ function grade_get_grades($courseid, $itemtype, $itemmodule, $iteminstance, $use

switch ($grade_item->gradetype) {
case GRADE_TYPE_NONE:
continue;
break;

case GRADE_TYPE_VALUE:
$item->scaleid = 0;
Expand Down
2 changes: 1 addition & 1 deletion mod/assign/feedback/editpdf/classes/combined_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function refresh_files() {
$status = $file->get('status');
switch ($status) {
case \core_files\conversion::STATUS_COMPLETE:
continue;
continue 2;
break;
default:
$converter->poll_conversion($conversion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function execute() {
case combined_document::STATUS_READY:
case combined_document::STATUS_PENDING_INPUT:
// The document has not been converted yet or is somehow still ready.
continue;
continue 2;
}
document_services::get_page_images_for_attempt(
$assignment,
Expand Down
5 changes: 2 additions & 3 deletions mod/assign/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,9 @@ function mod_assign_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionsubmit', 'assign');
}
$descriptions[] = get_string('completionsubmit', 'assign');
break;
default:
break;
Expand Down
6 changes: 3 additions & 3 deletions mod/chat/chatd.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public function cli_switch($switch, $param = null) {
if (!preg_match('/beep=([^&]*)[& ]/', $data, $info)) {
$daemon->trace('Beep sidekick did not contain a valid userid', E_USER_WARNING);
$daemon->dismiss_ufo($handle, true, 'Request with malformed data; connection closed');
continue;
continue 2;
} else {
$customdata = array('beep' => intval($info[1]));
}
Expand All @@ -1017,15 +1017,15 @@ public function cli_switch($switch, $param = null) {
if (!preg_match('/chat_message=([^&]*)[& ]chat_msgidnr=([^&]*)[& ]/', $data, $info)) {
$daemon->trace('Message sidekick did not contain a valid message', E_USER_WARNING);
$daemon->dismiss_ufo($handle, true, 'Request with malformed data; connection closed');
continue;
continue 2;
} else {
$customdata = array('message' => $info[1], 'index' => $info[2]);
}
break;
default:
$daemon->trace('UFO with '.$handle.': Request with unknown type; connection closed', E_USER_WARNING);
$daemon->dismiss_ufo($handle, true, 'Request with unknown type; connection closed');
continue;
continue 2;
break;
}

Expand Down
5 changes: 2 additions & 3 deletions mod/choice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,9 @@ function mod_choice_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionsubmit', 'choice');
}
$descriptions[] = get_string('completionsubmit', 'choice');
break;
default:
break;
Expand Down
5 changes: 2 additions & 3 deletions mod/data/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4555,10 +4555,9 @@ function mod_data_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionentries':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionentriesdesc', 'data', $val);
}
$descriptions[] = get_string('completionentriesdesc', 'data', $val);
break;
default:
break;
Expand Down
5 changes: 2 additions & 3 deletions mod/feedback/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3097,10 +3097,9 @@ function mod_feedback_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionsubmit', 'feedback');
}
$descriptions[] = get_string('completionsubmit', 'feedback');
break;
default:
break;
Expand Down
15 changes: 6 additions & 9 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -8563,22 +8563,19 @@ function mod_forum_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completiondiscussions':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completiondiscussionsdesc', 'forum', $val);
}
$descriptions[] = get_string('completiondiscussionsdesc', 'forum', $val);
break;
case 'completionreplies':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionrepliesdesc', 'forum', $val);
}
$descriptions[] = get_string('completionrepliesdesc', 'forum', $val);
break;
case 'completionposts':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionpostsdesc', 'forum', $val);
}
$descriptions[] = get_string('completionpostsdesc', 'forum', $val);
break;
default:
break;
Expand Down
5 changes: 2 additions & 3 deletions mod/glossary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4314,10 +4314,9 @@ function mod_glossary_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionentries':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionentriesdesc', 'glossary', $val);
}
$descriptions[] = get_string('completionentriesdesc', 'glossary', $val);
break;
default:
break;
Expand Down
10 changes: 4 additions & 6 deletions mod/lesson/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1745,16 +1745,14 @@ function mod_lesson_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionendreached':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionendreached_desc', 'lesson', $val);
}
$descriptions[] = get_string('completionendreached_desc', 'lesson', $val);
break;
case 'completiontimespent':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completiontimespentdesc', 'lesson', format_time($val));
}
$descriptions[] = get_string('completiontimespentdesc', 'lesson', format_time($val));
break;
default:
break;
Expand Down
10 changes: 4 additions & 6 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2266,16 +2266,14 @@ function mod_quiz_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionattemptsexhausted':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionattemptsexhausteddesc', 'quiz');
}
$descriptions[] = get_string('completionattemptsexhausteddesc', 'quiz');
break;
case 'completionpass':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionpassdesc', 'quiz', format_time($val));
}
$descriptions[] = get_string('completionpassdesc', 'quiz', format_time($val));
break;
default:
break;
Expand Down
31 changes: 14 additions & 17 deletions mod/scorm/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1778,30 +1778,27 @@ function mod_scorm_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionstatusrequired':
if (is_null($val)) {
continue;
}
// Determine the selected statuses using a bitwise operation.
$cvalues = array();
foreach (scorm_status_options(true) as $bit => $string) {
if (($val & $bit) == $bit) {
$cvalues[] = $string;
if (!is_null($val)) {
// Determine the selected statuses using a bitwise operation.
$cvalues = array();
foreach (scorm_status_options(true) as $bit => $string) {
if (($val & $bit) == $bit) {
$cvalues[] = $string;
}
}
$statusstring = implode(', ', $cvalues);
$descriptions[] = get_string('completionstatusrequireddesc', 'scorm', $statusstring);
}
$statusstring = implode(', ', $cvalues);
$descriptions[] = get_string('completionstatusrequireddesc', 'scorm', $statusstring);
break;
case 'completionscorerequired':
if (is_null($val)) {
continue;
if (!is_null($val)) {
$descriptions[] = get_string('completionscorerequireddesc', 'scorm', $val);
}
$descriptions[] = get_string('completionscorerequireddesc', 'scorm', $val);
break;
case 'completionstatusallscos':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionstatusallscos', 'scorm');
}
$descriptions[] = get_string('completionstatusallscos', 'scorm');
break;
default:
break;
Expand Down Expand Up @@ -1922,4 +1919,4 @@ function mod_scorm_core_calendar_get_valid_event_timestart_range(\calendar_event
}

return [$mindate, $maxdate];
}
}
5 changes: 2 additions & 3 deletions mod/survey/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,10 +1201,9 @@ function mod_survey_get_completion_active_rule_descriptions($cm) {
foreach ($cm->customdata['customcompletionrules'] as $key => $val) {
switch ($key) {
case 'completionsubmit':
if (empty($val)) {
continue;
if (!empty($val)) {
$descriptions[] = get_string('completionsubmit', 'survey');
}
$descriptions[] = get_string('completionsubmit', 'survey');
break;
default:
break;
Expand Down

0 comments on commit bd5fdcf

Please sign in to comment.