Skip to content

Commit 7f9968c

Browse files
committed
Update coding style
1 parent c5614a8 commit 7f9968c

19 files changed

+231
-230
lines changed

backup/moodle2/backup_qtype_varnumericset_plugin.class.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ protected function define_question_plugin_structure() {
5252
$this->add_question_qtype_varnumericset_vars($pluginwrapper);
5353

5454
// Now create the qtype own structures.
55-
$varnumericset = new backup_nested_element('varnumericset', array('id'), array(
56-
'randomseed', 'requirescinotation'));
55+
$varnumericset = new backup_nested_element('varnumericset', ['id'], [
56+
'randomseed', 'requirescinotation']);
5757

5858
// Now the own qtype tree.
5959
$pluginwrapper->add_child($varnumericset);
6060

6161
// Set source to populate the data.
6262
$varnumericset->set_source_table('qtype_varnumericset',
63-
array('questionid' => backup::VAR_PARENTID));
63+
['questionid' => backup::VAR_PARENTID]);
6464

6565
// Don't need to annotate ids nor files.
6666

@@ -76,8 +76,8 @@ protected function add_question_qtype_varnumericset_vars($element) {
7676

7777
// Define the elements.
7878
$vars = new backup_nested_element('vars');
79-
$var = new backup_nested_element('var', array('id'),
80-
array('varno', 'nameorassignment'));
79+
$var = new backup_nested_element('var', ['id'],
80+
['varno', 'nameorassignment']);
8181

8282
$this->add_question_qtype_varnumericset_variants($var);
8383

@@ -87,7 +87,7 @@ protected function add_question_qtype_varnumericset_vars($element) {
8787

8888
// Set source to populate the data.
8989
$var->set_source_table('qtype_varnumericset_vars',
90-
array('questionid' => backup::VAR_PARENTID));
90+
['questionid' => backup::VAR_PARENTID]);
9191
}
9292

9393
protected function add_question_qtype_varnumericset_variants($element) {
@@ -99,16 +99,16 @@ protected function add_question_qtype_varnumericset_variants($element) {
9999

100100
// Define the elements.
101101
$variants = new backup_nested_element('variants');
102-
$variant = new backup_nested_element('variant', array('id'),
103-
array('varid', 'variantno', 'value'));
102+
$variant = new backup_nested_element('variant', ['id'],
103+
['varid', 'variantno', 'value']);
104104

105105
// Build the tree.
106106
$element->add_child($variants);
107107
$variants->add_child($variant);
108108

109109
// Set source to populate the data.
110110
$variant->set_source_table('qtype_varnumericset_variants',
111-
array('varid' => backup::VAR_PARENTID));
111+
['varid' => backup::VAR_PARENTID]);
112112
}
113113
protected function add_question_qtype_varnumericset_answers($element) {
114114
// Check $element is one nested_backup_element.
@@ -119,9 +119,9 @@ protected function add_question_qtype_varnumericset_answers($element) {
119119

120120
// Define the elements.
121121
$answers = new backup_nested_element('varnumericset_answers');
122-
$answer = new backup_nested_element('varnumericset_answer', array('id'), array(
122+
$answer = new backup_nested_element('varnumericset_answer', ['id'], [
123123
'answerid', 'error', 'sigfigs', 'checknumerical', 'checkscinotation',
124-
'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat'));
124+
'checkpowerof10', 'checkrounding', 'syserrorpenalty', 'checkscinotationformat']);
125125

126126
// Build the tree.
127127
$element->add_child($answers);
@@ -134,7 +134,7 @@ protected function add_question_qtype_varnumericset_answers($element) {
134134
JOIN {question_answers} ans ON ans.id = vans.answerid
135135
WHERE ans.question = :question
136136
ORDER BY id',
137-
array('question' => backup::VAR_PARENTID));
137+
['question' => backup::VAR_PARENTID]);
138138
// Don't need to annotate ids or files.
139139
}
140140
}

backup/moodle2/restore_qtype_varnumericset_plugin.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class restore_qtype_varnumericset_plugin extends restore_qtype_plugin {
3434
*/
3535
protected function define_question_plugin_structure() {
3636

37-
$paths = array();
37+
$paths = [];
3838

3939
// This qtype uses question_answers, add them.
4040
$this->add_question_question_answers($paths);
4141

42-
$elements = array('qtype_varnumericset' => '/varnumericset',
42+
$elements = ['qtype_varnumericset' => '/varnumericset',
4343
'qtype_varnumericset_answer' => '/varnumericset_answers/varnumericset_answer',
4444
'qtype_varnumericset_var' => '/vars/var',
45-
'qtype_varnumericset_variant' => '/vars/var/variants/variant');
45+
'qtype_varnumericset_variant' => '/vars/var/variants/variant'];
4646
foreach ($elements as $elename => $path) {
4747
$elepath = $this->get_pathfor($path);
4848
$paths[] = new restore_path_element($elename, $elepath);

calculatorbase.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,27 @@ abstract class qtype_varnumeric_calculator_base {
4747
* @var array two dimensional array first key is varno,
4848
* 2nd is variant no, contents is value of variant.
4949
*/
50-
protected $predefinedvariants = array();
50+
protected $predefinedvariants = [];
5151

5252
/**
5353
* @var array two dimensional array first key is varno,
5454
* 2nd is variant no, contents is value of variant
5555
*/
56-
protected $calculatedvariants = array();
56+
protected $calculatedvariants = [];
5757

5858
/** @var array one dimensional array key is varno. **/
59-
protected $variables = array();
59+
protected $variables = [];
6060

6161
/** @var array one dimensional array first key is varno. **/
62-
protected $vartypes = array();
62+
protected $vartypes = [];
6363

6464
protected $noofvariants = 0;
6565

66-
protected $answers = array();
66+
protected $answers = [];
6767

68-
protected $textswithembeddedvars = array();
68+
protected $textswithembeddedvars = [];
6969

70-
protected $errors = array();
70+
protected $errors = [];
7171

7272
public function add_variable($varno, $variablenameorassignment) {
7373
$this->variables[$varno] = $variablenameorassignment;
@@ -76,7 +76,7 @@ public function add_variable($varno, $variablenameorassignment) {
7676
public function add_defined_variant($varno, $variantno, $value) {
7777
$this->noofvariants = max($this->noofvariants, $variantno + 1);
7878
if (!isset($this->predefinedvariants[$variantno])) {
79-
$this->predefinedvariants[$variantno] = array();
79+
$this->predefinedvariants[$variantno] = [];
8080
}
8181
$this->predefinedvariants[$variantno][$varno] = $value;
8282
}
@@ -148,7 +148,7 @@ public function evaluate_all($forcerecalculate = false) {
148148
$this->calculatedvariants[$variantno]
149149
= $this->calculate_calculated_variant_values($variantno);
150150
foreach ($this->answers as $answerno => $answer) {
151-
foreach (array('answer', 'error') as $prop) {
151+
foreach (['answer', 'error'] as $prop) {
152152
if ($prop == 'error' && $answer->{$prop} == '') {
153153
continue; // No error messages for blank allowed error fields in answer.
154154
}
@@ -215,7 +215,7 @@ public function evaluate_variant($variantno, $forcerecalculate = false) {
215215
}
216216

217217
protected function calculate_calculated_variant_values($variantno) {
218-
$calculatedvariants = array();
218+
$calculatedvariants = [];
219219
foreach ($this->variables as $varno => $variablenameorassignment) {
220220
if (self::is_assignment($variablenameorassignment)) {
221221
$varname = self::var_in_assignment($variablenameorassignment);
@@ -276,13 +276,13 @@ public function load_data_from_form($formdata) {
276276
}
277277
}
278278

279-
$this->add_text_with_embedded_variables($formdata, array('questiontext'));
280-
$this->add_text_with_embedded_variables($formdata, array('generalfeedback'));
279+
$this->add_text_with_embedded_variables($formdata, ['questiontext']);
280+
$this->add_text_with_embedded_variables($formdata, ['generalfeedback']);
281281

282-
foreach (array('feedback', 'hint') as $itemname) {
282+
foreach (['feedback', 'hint'] as $itemname) {
283283
if (isset($formdata[$itemname])) {
284284
foreach ($formdata[$itemname] as $indexno => $item) {
285-
$this->add_text_with_embedded_variables($formdata, array($itemname, $indexno));
285+
$this->add_text_with_embedded_variables($formdata, [$itemname, $indexno]);
286286
}
287287
}
288288
}
@@ -316,7 +316,7 @@ public function set_recalculate_rand($recalculateeverytime) {
316316

317317
public function load_data_from_database($vars, $variants) {
318318
// Declare and load data whether or not we will use calculator.
319-
$varidtovarno = array();
319+
$varidtovarno = [];
320320
foreach ($vars as $varid => $var) {
321321
if (self::is_assignment($var->nameorassignment)) {
322322
$this->vartypes[$var->varno] = 0;
@@ -341,7 +341,7 @@ public function get_data_for_form($dataforform) {
341341
$dataforform->varname = array_values($this->variables);
342342
for ($variantno = 0; $variantno < $this->get_num_variants_in_form(); $variantno++) {
343343
$propname = 'variant'.$variantno;
344-
$dataforform->{$propname} = array();
344+
$dataforform->{$propname} = [];
345345
if (isset($this->predefinedvariants[$variantno])) {
346346
$dataforform->{$propname} += array_values($this->predefinedvariants[$variantno]);
347347
}
@@ -384,7 +384,7 @@ public function evaluate_variables_in_text($text, $wheretoputerror = null) {
384384
// Match anything surrounded by [[ ]].
385385
preg_match_all('~\[\[(.+?)(\s*,\s*(.*?))?]]~', $text, $matches, PREG_SET_ORDER);
386386
foreach ($matches as $match) {
387-
// Since the format may, or may not, be present, append an extra empty string to $match;
387+
// Since the format may, or may not, be present, append an extra empty string to $match.
388388
[$placeholder, $variableorexpression, $hasformat, $format] = array_merge($match, ['', '']);
389389
if (isset($done[$placeholder])) {
390390
// The same placeholder always gets replaced by the same value.

classes/output/mobile.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public static function varnumset_view() {
3636
'templates' => [
3737
[
3838
'id' => 'main',
39-
'html' => file_get_contents($CFG->dirroot . '/question/type/varnumericset/mobile/varnumset.html')
39+
'html' => file_get_contents($CFG->dirroot . '/question/type/varnumericset/mobile/varnumset.html'),
4040
],
4141
],
42-
'javascript' => file_get_contents($CFG->dirroot . '/question/type/varnumericset/mobile/varnumset.js')
42+
'javascript' => file_get_contents($CFG->dirroot . '/question/type/varnumericset/mobile/varnumset.js'),
4343
];
4444
}
4545
}

db/mobile.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
'method' => 'varnumset_view',
3333
'styles' => [
3434
'url' => $CFG->wwwroot . '/question/type/varnumericset/mobileapp.css',
35-
'version' => 2019040200
35+
'version' => 2019040200,
3636
],
37-
'init' => 'varnumset_view'
37+
'init' => 'varnumset_view',
3838
],
3939
],
4040
'lang' => [ // Language strings to be used.
41-
['err_ousupsubnotsupportedonmobile', 'qtype_varnumericset']
42-
]
43-
]
41+
['err_ousupsubnotsupportedonmobile', 'qtype_varnumericset'],
42+
],
43+
],
4444
];

edit_varnumericset_form_base.php

+25-25
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ protected function definition_inner($mform) {
4545

4646
$answersoption = '';
4747

48-
$typemenu = array(0 => get_string('vartypecalculated', 'qtype_varnumericset'),
49-
1 => get_string('vartypepredefined', 'qtype_varnumericset'));
48+
$typemenu = [0 => get_string('vartypecalculated', 'qtype_varnumericset'),
49+
1 => get_string('vartypepredefined', 'qtype_varnumericset')];
5050

51-
$repeated = array();
52-
$repeatedoptions = array();
51+
$repeated = [];
52+
$repeatedoptions = [];
5353
$mform->addElement('header', 'variables',
5454
get_string('variables', 'qtype_varnumericset'));
5555
$repeated[] = $mform->createElement('select', 'vartype', '', $typemenu);
5656
$repeated[] = $mform->createElement('text', 'varname',
57-
get_string('varheader', 'qtype_varnumericset'), array('size' => 40));
57+
get_string('varheader', 'qtype_varnumericset'), ['size' => 40]);
5858

5959
$mform->setType('varname', PARAM_RAW_TRIMMED);
60-
$repeatedoptions['varname']['helpbutton'] = array('varname', 'qtype_varnumericset');
60+
$repeatedoptions['varname']['helpbutton'] = ['varname', 'qtype_varnumericset'];
6161

6262
list($repeated, $repeatedoptions) =
6363
$this->add_value_form_fields($mform, $repeated, $repeatedoptions);
@@ -147,11 +147,11 @@ protected function add_value_form_fields($mform, $repeated, $repeatedoptions) {
147147
}
148148
for ($i = 0; $i < $noofvariants; $i++) {
149149
$repeated[] = $mform->createElement('text', "variant$i",
150-
get_string('variant', 'qtype_varnumericset', $i + 1), array('size' => 40));
151-
$repeatedoptions["variant$i"]['disabledif'] = array('vartype', 'eq', 0);
150+
get_string('variant', 'qtype_varnumericset', $i + 1), ['size' => 40]);
151+
$repeatedoptions["variant$i"]['disabledif'] = ['vartype', 'eq', 0];
152152
if ($i == 0) {
153153
$repeatedoptions["variant$i"]['helpbutton']
154-
= array('variants', 'qtype_varnumericset');
154+
= ['variants', 'qtype_varnumericset'];
155155
}
156156
$mform->setType("variant$i", PARAM_RAW_TRIMMED);
157157
}
@@ -160,7 +160,7 @@ protected function add_value_form_fields($mform, $repeated, $repeatedoptions) {
160160
$mform->addElement('hidden', 'noofvariants', $noofvariants);
161161
$mform->setConstant('noofvariants', $noofvariants);
162162
$mform->setType('noofvariants', PARAM_INT);
163-
return array($repeated, $repeatedoptions);
163+
return [$repeated, $repeatedoptions];
164164
}
165165

166166
protected function add_value_form_last_field($mform, &$repeated, &$repeatedoptions) {
@@ -173,22 +173,22 @@ protected function add_value_form_last_field($mform, &$repeated, &$repeatedoptio
173173
* the start of the form.
174174
*/
175175
$repeated[] = $mform->createElement('text', "variant_last",
176-
'last variant', '', array('class' => 'last'));
176+
'last variant', '', ['class' => 'last']);
177177
$mform->setType('variant_last', PARAM_TEXT);
178178
}
179179

180180
protected function get_per_answer_fields($mform, $label, $gradeoptions,
181181
&$repeatedoptions, &$answersoption) {
182-
$repeated = array();
183-
$answeroptions = array();
182+
$repeated = [];
183+
$answeroptions = [];
184184

185185
// For this question type we are using a per answer header, a header for all answers won't really work.
186186
$mform->removeElement('answerhdr');
187187

188-
$answeroptions[] = $mform->createElement('text', 'answer', '', array('size' => 8));
189-
$answeroptions[] = $mform->createElement('text', 'error', get_string('error', 'qtype_varnumericset'), array('size' => 8));
190-
$sigfigsoptions = array(0 => get_string('unspecified', 'qtype_varnumericset'),
191-
1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6);
188+
$answeroptions[] = $mform->createElement('text', 'answer', '', ['size' => 8]);
189+
$answeroptions[] = $mform->createElement('text', 'error', get_string('error', 'qtype_varnumericset'), ['size' => 8]);
190+
$sigfigsoptions = [0 => get_string('unspecified', 'qtype_varnumericset'),
191+
1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6];
192192
$answeroptions[] = $mform->createElement('select', 'sigfigs', get_string('sigfigs', 'qtype_varnumericset'),
193193
$sigfigsoptions);
194194

@@ -197,29 +197,29 @@ protected function get_per_answer_fields($mform, $label, $gradeoptions,
197197
$label, $answeroptions, null, false);
198198

199199
$repeated[] = $mform->createElement('editor', 'feedback',
200-
get_string('feedback', 'question'), array('rows' => 5), $this->editoroptions);
200+
get_string('feedback', 'question'), ['rows' => 5], $this->editoroptions);
201201
$repeated[] = $mform->createElement('static', 'autofirehdr', '',
202202
get_string('autofirehdr', 'qtype_varnumericset', ''));
203-
$autofirerow1 = array();
203+
$autofirerow1 = [];
204204
$autofirerow1[] = $mform->createElement('selectyesno', 'checknumerical',
205205
get_string('checknumerical', 'qtype_varnumericset'));
206-
$checkpowerof10options = array(0 => get_string('no'),
206+
$checkpowerof10options = [0 => get_string('no'),
207207
1 => '+/- 1', 2 => '+/- 2', 3 => '+/- 3',
208-
4 => '+/- 4', 5 => '+/- 5', 6 => '+/- 6');
208+
4 => '+/- 4', 5 => '+/- 5', 6 => '+/- 6'];
209209
$autofirerow1[] = $mform->createElement('selectyesno', 'checkscinotation',
210210
get_string('checkscinotation', 'qtype_varnumericset'));
211211
$repeated[] = $mform->createElement('group', 'autofirerow1', '',
212212
$autofirerow1, null, false);
213213

214-
$autofirerow2 = array();
214+
$autofirerow2 = [];
215215
$autofirerow2[] = $mform->createElement('selectyesno', 'checkscinotationformat',
216216
get_string('checkscinotationformat', 'qtype_varnumericset'));
217217
$autofirerow2[] = $mform->createElement('select', 'checkpowerof10',
218218
get_string('checkpowerof10', 'qtype_varnumericset'), $checkpowerof10options);
219219
$repeated[] = $mform->createElement('group', 'autofirerow2', '',
220220
$autofirerow2, null, false);
221221

222-
$autofirerow3 = array();
222+
$autofirerow3 = [];
223223
$autofirerow3[] = $mform->createElement('selectyesno', 'checkrounding',
224224
get_string('checkrounding', 'qtype_varnumericset'));
225225
$autofirerow3[] = $mform->createElement('select', 'syserrorpenalty',
@@ -242,10 +242,10 @@ protected function get_hint_fields($withclearwrong = false, $withshownumpartscor
242242
parent::get_hint_fields(false, false);
243243
$repeated[] = $mform->createElement('advcheckbox', 'hintclearwrong',
244244
get_string('options', 'qtype_varnumericset'),
245-
get_string('hintoverride', 'qtype_varnumericset'), null, array(0, 1));
245+
get_string('hintoverride', 'qtype_varnumericset'), null, [0, 1]);
246246
$repeatedoptions['hintclearwrong']['type'] = PARAM_BOOL;
247247

248-
return array($repeated, $repeatedoptions);
248+
return [$repeated, $repeatedoptions];
249249
}
250250

251251
protected function data_preprocessing($question) {

lib.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* Checks file access for varnumeric set questions.
2929
*/
30-
function qtype_varnumericset_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
30+
function qtype_varnumericset_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options= []) {
3131
global $DB, $CFG;
3232
require_once($CFG->libdir . '/questionlib.php');
3333
question_pluginfile($course, $context, 'qtype_varnumericset', $filearea, $args, $forcedownload, $options);

0 commit comments

Comments
 (0)