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 44315f2
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 157 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
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.

4 changes: 2 additions & 2 deletions tests/form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,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 +83,7 @@ public function form_validation_testcases(): array {
'variant0' => [],
'variant1' => [],
],
[]
[],
],
];
}
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
24 changes: 11 additions & 13 deletions tests/question_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Unit tests for the varnumeric question definition class.
*
* @package qtype_varnumeric
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace qtype_varnumeric;

use basic_testcase;
use qtype_varnumeric_question;

defined('MOODLE_INTERNAL') || die();
global $CFG;
Expand All @@ -32,12 +29,13 @@
/**
* Unit tests for the varnumeric question definition class.
*
* @package qtype_varnumeric
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @group qtype_varnumeric
* @covers \qtype_varnumeric_question
*/
class qtype_varnumeric_question_test extends basic_testcase {
public function test_wrong_by_a_factor_of_ten() {
class question_test extends basic_testcase {
public function test_wrong_by_a_factor_of_ten(): void {
$this->assertTrue(
qtype_varnumeric_question::wrong_by_a_factor_of_ten('1.23e4', 1.23e5, '', 1));
$this->assertFalse(
Expand All @@ -52,7 +50,7 @@ public function test_wrong_by_a_factor_of_ten() {
qtype_varnumeric_question::wrong_by_a_factor_of_ten('152000', 150, 1, 3));
}

public function test_has_number_of_sig_figs() {
public function test_has_number_of_sig_figs(): void {
$this->assertTrue(
qtype_varnumeric_question::has_number_of_sig_figs('1.23e4', 3));
$this->assertTrue(
Expand All @@ -75,7 +73,7 @@ public function test_has_number_of_sig_figs() {
qtype_varnumeric_question::has_number_of_sig_figs('152000', 2));
}

public function test_has_too_many_sig_figs() {
public function test_has_too_many_sig_figs(): void {
$this->assertTrue(
qtype_varnumeric_question::has_too_many_sig_figs('1.23456', 1.23456, 2));
$this->assertTrue(
Expand All @@ -98,7 +96,7 @@ public function test_has_too_many_sig_figs() {
qtype_varnumeric_question::has_too_many_sig_figs('-1.23456e-12', -1.2346e-12, 4));
}

public function test_rounding_incorrect() {
public function test_rounding_incorrect(): void {
$this->assertTrue(
qtype_varnumeric_question::rounding_incorrect('1.234', 1.2345, 4));
$this->assertTrue(
Expand Down
Loading

0 comments on commit 44315f2

Please sign in to comment.