diff --git a/backup/moodle2/backup_qtype_varnumeric_plugin.class.php b/backup/moodle2/backup_qtype_varnumeric_plugin.class.php index 1611297..c10ce95 100644 --- a/backup/moodle2/backup_qtype_varnumeric_plugin.class.php +++ b/backup/moodle2/backup_qtype_varnumeric_plugin.class.php @@ -52,15 +52,15 @@ protected function define_question_plugin_structure() { $this->add_question_qtype_varnumeric_vars($pluginwrapper); // Now create the qtype own structures. - $varnumeric = new backup_nested_element('varnumeric', array('id'), array( - 'randomseed', 'recalculateeverytime', 'requirescinotation')); + $varnumeric = new backup_nested_element('varnumeric', ['id'], [ + 'randomseed', 'recalculateeverytime', 'requirescinotation']); // Now the own qtype tree. $pluginwrapper->add_child($varnumeric); // Set source to populate the data. $varnumeric->set_source_table('qtype_varnumeric', - array('questionid' => backup::VAR_PARENTID)); + ['questionid' => backup::VAR_PARENTID]); // Don't need to annotate ids nor files. @@ -75,8 +75,8 @@ protected function add_question_qtype_varnumeric_vars($element) { // Define the elements. $vars = new backup_nested_element('vars'); - $var = new backup_nested_element('var', array('id'), - array('varno', 'nameorassignment')); + $var = new backup_nested_element('var', ['id'], + ['varno', 'nameorassignment']); $this->add_question_qtype_varnumeric_variants($var); @@ -86,7 +86,7 @@ protected function add_question_qtype_varnumeric_vars($element) { // Set source to populate the data. $var->set_source_table('qtype_varnumeric_vars', - array('questionid' => backup::VAR_PARENTID)); + ['questionid' => backup::VAR_PARENTID]); } protected function add_question_qtype_varnumeric_variants($element) { @@ -98,8 +98,8 @@ protected function add_question_qtype_varnumeric_variants($element) { // Define the elements. $variants = new backup_nested_element('variants'); - $variant = new backup_nested_element('variant', array('id'), - array('varid', 'variantno', 'value')); + $variant = new backup_nested_element('variant', ['id'], + ['varid', 'variantno', 'value']); // Build the tree. $element->add_child($variants); @@ -107,7 +107,7 @@ protected function add_question_qtype_varnumeric_variants($element) { // Set source to populate the data. $variant->set_source_table('qtype_varnumeric_variants', - array('varid' => backup::VAR_PARENTID)); + ['varid' => backup::VAR_PARENTID]); } protected function add_question_qtype_varnumeric_answers($element) { // Check $element is one nested_backup_element. @@ -118,9 +118,9 @@ protected function add_question_qtype_varnumeric_answers($element) { // Define the elements. $answers = new backup_nested_element('varnumeric_answers'); - $answer = new backup_nested_element('varnumeric_answer', array('id'), array( + $answer = new backup_nested_element('varnumeric_answer', ['id'], [ 'answerid', 'error', 'sigfigs', 'checknumerical', 'checkscinotation', - 'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat')); + 'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat']); // Build the tree. $element->add_child($answers); @@ -133,7 +133,7 @@ protected function add_question_qtype_varnumeric_answers($element) { JOIN {question_answers} ans ON ans.id = vans.answerid WHERE ans.question = :question ORDER BY id', - array('question' => backup::VAR_PARENTID)); + ['question' => backup::VAR_PARENTID]); // Don't need to annotate ids or files. } } diff --git a/backup/moodle2/restore_qtype_varnumeric_plugin.class.php b/backup/moodle2/restore_qtype_varnumeric_plugin.class.php index 9f02838..41d7509 100644 --- a/backup/moodle2/restore_qtype_varnumeric_plugin.class.php +++ b/backup/moodle2/restore_qtype_varnumeric_plugin.class.php @@ -34,15 +34,15 @@ class restore_qtype_varnumeric_plugin extends restore_qtype_plugin { */ protected function define_question_plugin_structure() { - $paths = array(); + $paths = []; // This qtype uses question_answers, add them. $this->add_question_question_answers($paths); - $elements = array('qtype_varnumeric' => '/varnumeric', + $elements = ['qtype_varnumeric' => '/varnumeric', 'qtype_varnumeric_answer' => '/varnumeric_answers/varnumeric_answer', 'qtype_varnumeric_var' => '/vars/var', - 'qtype_varnumeric_variant' => '/vars/var/variants/variant'); + 'qtype_varnumeric_variant' => '/vars/var/variants/variant']; foreach ($elements as $elename => $path) { $elepath = $this->get_pathfor($path); $paths[] = new restore_path_element($elename, $elepath); diff --git a/combinable/combinable.php b/combinable/combinable.php index 9903f0e..e02a5c0 100644 --- a/combinable/combinable.php +++ b/combinable/combinable.php @@ -54,13 +54,13 @@ class qtype_combined_combinable_varnumeric extends qtype_combined_combinable_tex public function add_form_fragment(moodleform $combinedform, MoodleQuickForm $mform, $repeatenabled) { - $answergroupels = array(); + $answergroupels = []; $answergroupels[] = $mform->createElement('text', $this->form_field_name('answer[0]'), - get_string('answer', 'question'), array('size' => 25)); + get_string('answer', 'question'), ['size' => 25]); $answergroupels[] = $mform->createElement('text', $this->form_field_name('error[0]'), get_string('error', 'qtype_varnumericset'), - array('size' => 16)); + ['size' => 16]); $mform->setType($this->form_field_name('answer'), PARAM_RAW); $mform->setType($this->form_field_name('error'), PARAM_RAW); $mform->addElement('group', @@ -78,7 +78,7 @@ public function add_form_fragment(moodleform $combinedform, MoodleQuickForm $mfo } public function data_to_form($context, $fileoptions) { - $numericoptions = array('answer' => array(), 'error' => array()); + $numericoptions = ['answer' => [], 'error' => []]; if ($this->questionrec !== null) { foreach ($this->questionrec->options->answers as $answer) { @@ -94,7 +94,7 @@ public function data_to_form($context, $fileoptions) { } public function validate() { - $errors = array(); + $errors = []; $interpret = new qtype_varnumericset_number_interpreter_number_with_optional_sci_notation(false); if ('' !== trim($this->formdata->error[0])) { if (!$interpret->match($this->formdata->error[0])) { diff --git a/edit_varnumeric_form.php b/edit_varnumeric_form.php index 606f190..efac25f 100644 --- a/edit_varnumeric_form.php +++ b/edit_varnumeric_form.php @@ -45,12 +45,12 @@ public function definition_inner($mform) { protected function add_value_form_fields($mform, $repeated, $repeatedoptions) { $repeated[] = $mform->createElement('text', "variant0", - get_string('value', 'qtype_varnumeric'), array('size' => 40)); - $repeatedoptions["variant0"]['disabledif'] = array('vartype', 'eq', 0); - $repeatedoptions["variant0"]['helpbutton'] = array('value', 'qtype_varnumeric'); + get_string('value', 'qtype_varnumeric'), ['size' => 40]); + $repeatedoptions["variant0"]['disabledif'] = ['vartype', 'eq', 0]; + $repeatedoptions["variant0"]['helpbutton'] = ['value', 'qtype_varnumeric']; $mform->setType("variant0", PARAM_RAW_TRIMMED); $this->add_value_form_last_field($mform, $repeated, $repeatedoptions); - return array($repeated, $repeatedoptions); + return [$repeated, $repeatedoptions]; } protected function validate_variables(int $countvariable, int $maxvariantno): array { diff --git a/lib.php b/lib.php index 553c3e6..e878a2c 100644 --- a/lib.php +++ b/lib.php @@ -26,7 +26,7 @@ /** * Checks file access for varnumeric questions. */ -function qtype_varnumeric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { +function qtype_varnumeric_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options= []) { global $DB, $CFG; require_once($CFG->libdir . '/questionlib.php'); question_pluginfile($course, $context, 'qtype_varnumeric', $filearea, $args, $forcedownload, $options); diff --git a/tests/evalmathsclass_test.php b/tests/evalmathsclass_test.php index 27932f9..414acbf 100644 --- a/tests/evalmathsclass_test.php +++ b/tests/evalmathsclass_test.php @@ -51,7 +51,7 @@ public function test_basic_expressions() { public function test_random_expressions() { $ev = new EvalMath(true, true); - $results = array(); + $results = []; for ($i = 0; $i < 500; $i++) { $ev->evaluate("a$i=rand_float()"); $results[] = $ev->evaluate("a$i"); @@ -60,7 +60,7 @@ public function test_random_expressions() { $this->assertTrue(max($results) <= 1); $ev = new EvalMath(true, true); - $results = array(); + $results = []; for ($i = 0; $i < 500; $i++) { $ev->evaluate("a$i=rand_int(500,1000)"); $results[] = $ev->evaluate("a$i"); diff --git a/tests/helper.php b/tests/helper.php index c5d4a37..edf2d1a 100644 --- a/tests/helper.php +++ b/tests/helper.php @@ -31,7 +31,7 @@ */ class qtype_varnumeric_test_helper extends question_test_helper { public function get_test_questions() { - return array('no_accepted_error', 'with_variables'); + return ['no_accepted_error', 'with_variables']; } /** @@ -40,11 +40,11 @@ public function get_test_questions() { public function get_varnumeric_question_form_data_no_accepted_error() { $form = new stdClass(); $form->name = 'Pi to two d.p.'; - $form->questiontext = array(); + $form->questiontext = []; $form->questiontext['format'] = '1'; $form->questiontext['text'] = 'What is pi to two d.p.?'; $form->defaultmark = 1; - $form->generalfeedback = array(); + $form->generalfeedback = []; $form->generalfeedback['format'] = '1'; $form->generalfeedback['text'] = 'Generalfeedback: 3.14 is the right answer.'; $form->randomseed = ''; diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php index 7564bf0..2ca2216 100644 --- a/tests/questiontype_test.php +++ b/tests/questiontype_test.php @@ -37,10 +37,10 @@ * @group qtype_varnumeric */ class qtype_varnumeric_test extends basic_testcase { - public static $includecoverage = array( + public static $includecoverage = [ 'question/type/questiontype.php', 'question/type/varnumeric/questiontype.php', - ); + ]; protected $qtype; @@ -52,8 +52,8 @@ protected function get_test_question_data() { $q = new stdClass(); $q->id = 1; $q->options = new stdClass(); - $q->options->answers[1] = (object) array('answer' => 'frog', 'fraction' => 1); - $q->options->answers[2] = (object) array('answer' => '*', 'fraction' => 0.1); + $q->options->answers[1] = (object) ['answer' => 'frog', 'fraction' => 1]; + $q->options->answers[2] = (object) ['answer' => '*', 'fraction' => 0.1]; return $q; } @@ -74,11 +74,11 @@ public function test_get_random_guess_score() { public function test_get_possible_responses() { $q = $this->get_test_question_data(); - $this->assertEquals(array( - $q->id => array( + $this->assertEquals([ + $q->id => [ 1 => new question_possible_response('frog', 1), 2 => new question_possible_response('*', 0.1), - null => question_possible_response::no_response()), - ), $this->qtype->get_possible_responses($q)); + null => question_possible_response::no_response()], + ], $this->qtype->get_possible_responses($q)); } } diff --git a/tests/stats_from_steps_walkthrough_test.php b/tests/stats_from_steps_walkthrough_test.php index 72bc4a6..75a71ef 100644 --- a/tests/stats_from_steps_walkthrough_test.php +++ b/tests/stats_from_steps_walkthrough_test.php @@ -54,7 +54,7 @@ protected function get_full_path_of_csv_file($setname, $test): string { return __DIR__."/fixtures/{$setname}{$test}.csv"; } - protected $files = array('questions', 'steps'); + protected $files = ['questions', 'steps']; /** * Create a quiz add questions to it, walk through quiz attempts and then check results. @@ -95,7 +95,7 @@ public function test_walkthrough_from_csv($quizsettings, $csvdata) { $analysis = $responesstats->load_cached($qubaids, $whichtries); $variantsnos = $analysis->get_variant_nos(); - $this->assertEquals(array(1), $variantsnos); + $this->assertEquals([1], $variantsnos); $total = 0; $subpartids = $analysis->get_subpart_ids(1); $subpartid = current($subpartids);