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 f9128bb
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 187 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
4 changes: 2 additions & 2 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static function varnum_view() {
'templates' => [
[
'id' => 'main',
'html' => file_get_contents($CFG->dirroot . '/question/type/varnumeric/mobile/varnum.html')
'html' => file_get_contents($CFG->dirroot . '/question/type/varnumeric/mobile/varnum.html'),
],
],
'javascript' => file_get_contents($CFG->dirroot . '/question/type/varnumeric/mobile/varnum.js')
'javascript' => file_get_contents($CFG->dirroot . '/question/type/varnumeric/mobile/varnum.js'),
];
}
}
16 changes: 8 additions & 8 deletions combinable/combinable.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ class qtype_combined_combinable_type_varnumeric extends qtype_combined_combinabl
protected $identifier = 'numeric';

protected function extra_question_properties() {
return ['randomseed' => '', 'vartype' => [0], 'varname' => [''], 'variant' => [''], 'novars' => 1,];
return ['randomseed' => '', 'vartype' => [0], 'varname' => [''], 'variant' => [''], 'novars' => 1];
}

protected function extra_answer_properties() {
return ['sigfigs' => 0, 'fraction' => '1.0', 'checknumerical' => 0, 'checkscinotation' => 0,
'checkpowerof10' => 0, 'checkrounding' => 0, 'syserrorpenalty' => '0.0', 'checkscinotationformat' => 0,];
'checkpowerof10' => 0, 'checkrounding' => 0, 'syserrorpenalty' => '0.0', 'checkscinotationformat' => 0];
}

public function subq_form_fragment_question_option_fields() {
return ['requirescinotation' => null,];
return ['requirescinotation' => null];
}

protected function third_param_for_default_question_text() {
Expand All @@ -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
10 changes: 5 additions & 5 deletions db/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
'method' => 'varnum_view',
'styles' => [
'url' => $CFG->wwwroot . '/question/type/varnumericset/mobileapp.css',
'version' => 2019040200
'version' => 2019040200,
],
'init' => 'varnum_view'
'init' => 'varnum_view',
],
],
'lang' => [ // Language strings to be used.
['err_ousupsubnotsupportedonmobile', 'qtype_varnumericset']
]
]
['err_ousupsubnotsupportedonmobile', 'qtype_varnumericset'],
],
],
];
12 changes: 4 additions & 8 deletions edit_varnumeric_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,14 @@ public function qtype() {
return 'varnumeric';
}

public function definition_inner($mform) {
parent::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
2 changes: 1 addition & 1 deletion tests/behat/preview.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: Preview a Variable numeric question
| Marked out of | 3 |
| Question variant | 1 |
| Marks | Show mark and max |
And I press "Start again with these options"
And I press "id_saverestart"
Then I should see "What is 2 + 8?"
And the state of "What is 2 + 8?" question is shown as "Tries remaining: 3"
When I set the field "Answer:" to "2"
Expand Down
70 changes: 0 additions & 70 deletions tests/evalmathsclass_test.php

This file was deleted.

16 changes: 4 additions & 12 deletions tests/form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

namespace qtype_varnumeric;

/**
* Unit tests for the varnumeric question edit form.
*
* @package qtype_varnumeric
* @copyright 2023 The Open University
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
global $CFG;

Expand All @@ -34,10 +26,10 @@
/**
* Unit tests for the qtype_varnumeric question edit form.
*
* @package qtype_varnumeric
* @copyright 2023 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_varnumeric
* @covers qtype_varnumeric_edit_form
* @covers \qtype_varnumeric_edit_form
*/
class form_test extends \qtype_varnumericset\form_test {

Expand Down Expand Up @@ -71,7 +63,7 @@ public function test_form_validation(array $fromform, array $expectederrors): vo
*
* @return array List of data sets (test cases).
*/
public function form_validation_testcases(): array {
public static function form_validation_testcases(): array {
return [
'1 pre-defined variable' => [
[
Expand All @@ -83,7 +75,7 @@ public function form_validation_testcases(): array {
'variant0' => [],
'variant1' => [],
],
[]
[],
],
];
}
Expand Down
12 changes: 6 additions & 6 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 All @@ -70,7 +70,7 @@ public function get_varnumeric_question_form_data_no_accepted_error() {
'2' => ['format' => FORMAT_HTML, 'text' => ''],
'3' => ['format' => FORMAT_HTML, 'text' => ''],
'4' => ['format' => FORMAT_HTML, 'text' => ''],
'5' => ['format' => FORMAT_HTML, 'text' => '']
'5' => ['format' => FORMAT_HTML, 'text' => ''],
];
return $form;
}
Expand Down Expand Up @@ -131,12 +131,12 @@ public function get_varnumeric_question_form_data_with_variables() {
$form->fraction = ['0' => '1.0', '1' => '0.0', '2' => '0.0'];
$form->feedback = [
'0' => ['format' => FORMAT_HTML, 'text' => 'Well done!'],
'1' => ['format' => FORMAT_HTML, 'text' => 'Sorry, no.']
'1' => ['format' => FORMAT_HTML, 'text' => 'Sorry, no.'],
];
$form->penalty = '0.3333333';
$form->hint = [
['text' => 'Please try again.', 'format' => FORMAT_HTML],
['text' => 'You may use a calculator if necessary.', 'format' => FORMAT_HTML]
['text' => 'You may use a calculator if necessary.', 'format' => FORMAT_HTML],
];

return $form;
Expand Down
Loading

0 comments on commit f9128bb

Please sign in to comment.