From 7000a99de340bc1333398ce0751c19b87c183be5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 9 Jan 2023 11:43:30 +0800 Subject: [PATCH] MDL-76362 core: Coding style fixes --- .../helper/restore_structure_parser_processor.class.php | 6 ++++-- backup/util/xml/output/xml_output.class.php | 2 +- backup/util/xml/xml_writer.class.php | 2 +- grade/report/singleview/classes/local/screen/user.php | 9 ++++----- lib/filestorage/file_storage.php | 2 +- lib/mathslib.php | 2 +- mod/workshop/classes/portfolio_caller.php | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/backup/util/helper/restore_structure_parser_processor.class.php b/backup/util/helper/restore_structure_parser_processor.class.php index fdd9cb927bc..67a7a2d9213 100644 --- a/backup/util/helper/restore_structure_parser_processor.class.php +++ b/backup/util/helper/restore_structure_parser_processor.class.php @@ -55,8 +55,10 @@ class restore_structure_parser_processor extends grouped_parser_processor { return ''; } else if (is_numeric($cdata)) { return $cdata; - } else if (strlen($cdata ?? '') < 32) { // Impossible to have one link in 32cc - return $cdata; // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=) + } else if (strlen($cdata ?? '') < 32) { + // Impossible to have one link in 32cc. + // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=). + return $cdata; } if (strpos($cdata, '$@FILEPHP@$') !== false) { diff --git a/backup/util/xml/output/xml_output.class.php b/backup/util/xml/output/xml_output.class.php index 942c8ec1579..059c2f95a08 100644 --- a/backup/util/xml/output/xml_output.class.php +++ b/backup/util/xml/output/xml_output.class.php @@ -107,7 +107,7 @@ abstract class xml_output { if (!$this->running) { throw new xml_output_exception('xml_output_not_started'); } - $lenc = strlen($content ?? ''); // Get length in bytes + $lenc = strlen($content ?? ''); // Get length in bytes. if ($lenc == 0) { // 0 length contents, nothing to do return; } diff --git a/backup/util/xml/xml_writer.class.php b/backup/util/xml/xml_writer.class.php index 39ebeeaa73d..4673e4da3d4 100644 --- a/backup/util/xml/xml_writer.class.php +++ b/backup/util/xml/xml_writer.class.php @@ -260,7 +260,7 @@ class xml_writer { * ignores the rest of characters. Also normalize linefeeds and return chars. */ protected function xml_safe_utf8($content) { - $content = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is','', $content ?? ''); // clean CTRL chars + $content = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $content ?? ''); // clean CTRL chars. $content = preg_replace("/\r\n|\r/", "\n", $content); // Normalize line&return=>line return $content; } diff --git a/grade/report/singleview/classes/local/screen/user.php b/grade/report/singleview/classes/local/screen/user.php index fb3a4b2a56a..efeffe92bb1 100644 --- a/grade/report/singleview/classes/local/screen/user.php +++ b/grade/report/singleview/classes/local/screen/user.php @@ -405,16 +405,15 @@ class user extends tablelike implements selectable_items { $gradeitem = grade_item::fetch([ 'courseid' => $this->courseid, - 'id' => $matches[1] + 'id' => $matches[1], ]); $isscale = ($gradeitem->gradetype == GRADE_TYPE_SCALE); - $empties = (trim($value ?? '') === '' or ($isscale and $value == -1)); + $empties = (trim($value ?? '') === '' || ($isscale && $value == -1)); - if ($filter == 'all' or $empties) { - $data->$varname = ($isscale and empty($insertvalue)) ? - -1 : $insertvalue; + if ($filter == 'all' || $empties) { + $data->$varname = ($isscale && empty($insertvalue)) ? -1 : $insertvalue; } } } diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index 8fe268de6ca..e3a852271ff 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -1800,7 +1800,7 @@ class file_storage { // the latter of which can go to 100, we need to make sure that quality here is // in a safe range or PHP WILL CRASH AND DIE. You have been warned. $quality = $quality > 9 ? (int)(max(1.0, (float)$quality / 100.0) * 9.0) : $quality; - imagepng($img, NULL, $quality, PNG_NO_FILTER); + imagepng($img, null, $quality, PNG_NO_FILTER); break; default: diff --git a/lib/mathslib.php b/lib/mathslib.php index 0b33da3b9d7..6cee99a3e32 100644 --- a/lib/mathslib.php +++ b/lib/mathslib.php @@ -123,7 +123,7 @@ class calc_formula { * @return string localised formula */ public static function localize($formula) { - $formula = str_replace('.', '$', $formula ?? ''); // temp placeholder + $formula = str_replace('.', '$', $formula ?? ''); // Temp placeholder. $formula = str_replace(',', get_string('listsep', 'langconfig'), $formula); $formula = str_replace('$', get_string('decsep', 'langconfig'), $formula); return $formula; diff --git a/mod/workshop/classes/portfolio_caller.php b/mod/workshop/classes/portfolio_caller.php index eb618fb7192..aaaad77f630 100644 --- a/mod/workshop/classes/portfolio_caller.php +++ b/mod/workshop/classes/portfolio_caller.php @@ -342,7 +342,7 @@ class mod_workshop_portfolio_caller extends portfolio_module_caller_base { } if ($this->workshop->overallfeedbackmode) { - if ($assessment->feedbackauthorattachment or trim($assessment->feedbackauthor ?? '') !== '') { + if ($assessment->feedbackauthorattachment || trim($assessment->feedbackauthor ?? '') !== '') { $output .= html_writer::tag('h3', get_string('overallfeedback', 'mod_workshop')); $content = $this->format_exported_text($assessment->feedbackauthor, $assessment->feedbackauthorformat); $content = portfolio_rewrite_pluginfile_urls($content, $this->workshop->context->id, 'mod_workshop',