Skip to content

Commit

Permalink
Fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Feb 14, 2024
1 parent 44ba0a4 commit a41258d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 40 deletions.
24 changes: 12 additions & 12 deletions backup/moodle2/backup_qtype_varnumeric_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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);

Expand All @@ -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) {
Expand All @@ -98,16 +98,16 @@ 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);
$variants->add_child($variant);

// 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.
Expand All @@ -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);
Expand All @@ -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.
}
}
6 changes: 3 additions & 3 deletions backup/moodle2/restore_qtype_varnumeric_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions combinable/combinable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand All @@ -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])) {
Expand Down
8 changes: 4 additions & 4 deletions edit_varnumeric_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/evalmathsclass_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
Expand All @@ -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 = '';
Expand Down
16 changes: 8 additions & 8 deletions tests/questiontype_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand All @@ -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));
}
}
4 changes: 2 additions & 2 deletions tests/stats_from_steps_walkthrough_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a41258d

Please sign in to comment.