Skip to content

Commit

Permalink
MDL-20636 fix some more coding style issues in the question code.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed May 20, 2011
1 parent 449bfe9 commit e073681
Show file tree
Hide file tree
Showing 24 changed files with 170 additions and 375 deletions.
1 change: 1 addition & 0 deletions local/qeupgradehelper/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ function local_qeupgradehelper_format_var($name, $var) {
$out = preg_replace('/\n (?! )/', "\n ", $out);
$out = preg_replace('/\n (?! )/', "\n ", $out);
$out = preg_replace('/\n(?! )/', "\n ", $out);
$out = preg_replace('/\bNULL\b/', 'null', $out);
return " $name = $out;\n";
}

Expand Down
2 changes: 1 addition & 1 deletion question/category_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public function update_category($updateid, $newparent, $newname, $newinfo) {
}

// Update the category record.
$cat = NULL;
$cat = null;
$cat->id = $updateid;
$cat->name = $newname;
$cat->info = $newinfo;
Expand Down
2 changes: 1 addition & 1 deletion question/editlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ function question_edit_setup($edittab, $baseurl, $requirecmid = false, $requirec
$contextlist = join($contextlistarr, ' ,');
if (!empty($pagevars['cat'])){
$catparts = explode(',', $pagevars['cat']);
if (!$catparts[0] || (FALSE !== array_search($catparts[1], $contextlistarr)) ||
if (!$catparts[0] || (false !== array_search($catparts[1], $contextlistarr)) ||
!$DB->count_records_select("question_categories", "id = ? AND contextid = ?", array($catparts[0], $catparts[1]))) {
print_error('invalidcategory', 'question');
}
Expand Down
8 changes: 4 additions & 4 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
class qformat_default {

public $displayerrors = true;
public $category = NULL;
public $category = null;
public $questions = array();
public $course = NULL;
public $course = null;
public $filename = '';
public $realfilename = '';
public $matchgrades = 'error';
Expand Down Expand Up @@ -602,7 +602,7 @@ protected function readquestion($lines) {
$formatnotimplemented = get_string('formatnotimplemented', 'question');
echo "<p>$formatnotimplemented</p>";

return NULL;
return null;
}

/**
Expand Down Expand Up @@ -834,7 +834,7 @@ protected function writequestion($question) {
// if not overidden, then this is an error.
$formatnotimplemented = get_string('formatnotimplemented', 'question');
echo "<p>$formatnotimplemented</p>";
return NULL;
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions question/type/calculated/edit_calculated_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ public function validation($data, $files) {
return $errors;
}

function is_valid_answer($answer, $data) {
protected function is_valid_answer($answer, $data) {
return !qtype_calculated_find_formula_errors($answer);
}

function valid_answer_message($answer) {
protected function valid_answer_message($answer) {
if (!$answer) {
return get_string('mustenteraformulaorstar', 'qtype_numerical');
} else {
Expand Down
29 changes: 15 additions & 14 deletions question/type/calculated/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function calculate_all_expressions() {
* is to work with {@link qtype_calculated_question_helper}.
*
* As well as this method, the class that implements this interface must have
* fields
* fields
* public $datasetloader; // of type qtype_calculated_dataset_loader
* public $vs; // of type qtype_calculated_variable_substituter
*
Expand Down Expand Up @@ -322,7 +322,7 @@ public function format_float($x, $length = null, $format = null) {

/**
* Return an array of the variables and their values.
* @return array name => value.
* @return array name => value.
*/
public function get_values() {
return $this->values;
Expand Down Expand Up @@ -404,13 +404,13 @@ public function get_formula_errors($formula) {
while (preg_match('~\\{[[:alpha:]][^>} <{"\']*\\}~', $formula, $regs)) {
$formula = str_replace($regs[0], '1', $formula);
}

// Strip away empty space and lowercase it
$formula = strtolower(str_replace(' ', '', $formula));

$safeoperatorchar = '-+/*%>:^\~<?=&|!'; /* */
$operatorornumber = "[$safeoperatorchar.0-9eE]";

while (preg_match("~(^|[$safeoperatorchar,(])([a-z0-9_]*)" .
"\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)~",
$formula, $regs)) {
Expand All @@ -421,14 +421,14 @@ public function get_formula_errors($formula) {
return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
}
break;

// Zero argument functions
case 'pi':
if ($regs[3]) {
return get_string('functiontakesnoargs', 'qtype_calculated', $regs[2]);
}
break;

// Single argument functions (the most common case)
case 'abs': case 'acos': case 'acosh': case 'asin': case 'asinh':
case 'atan': case 'atanh': case 'bindec': case 'ceil': case 'cos':
Expand All @@ -441,32 +441,33 @@ public function get_formula_errors($formula) {
return get_string('functiontakesonearg', 'qtype_calculated', $regs[2]);
}
break;

// Functions that take one or two arguments
case 'log': case 'round':
if (!empty($regs[5]) || empty($regs[3])) {
return get_string('functiontakesoneortwoargs', 'qtype_calculated', $regs[2]);
return get_string('functiontakesoneortwoargs', 'qtype_calculated',
$regs[2]);
}
break;

// Functions that must have two arguments
case 'atan2': case 'fmod': case 'pow':
if (!empty($regs[5]) || empty($regs[4])) {
return get_string('functiontakestwoargs', 'qtype_calculated', $regs[2]);
}
break;

// Functions that take two or more arguments
case 'min': case 'max':
if (empty($regs[4])) {
return get_string('functiontakesatleasttwo', 'qtype_calculated', $regs[2]);
}
break;

default:
return get_string('unsupportedformulafunction', 'qtype_calculated', $regs[2]);
}

// Exchange the function call with '1' and then chack for
// another function call...
if ($regs[1]) {
Expand All @@ -477,7 +478,7 @@ public function get_formula_errors($formula) {
$formula = preg_replace("~^$regs[2]\\([^)]*\\)~", '1', $formula);
}
}

if (preg_match("~[^$safeoperatorchar.0-9eE]+~", $formula, $regs)) {
return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
} else {
Expand Down
3 changes: 2 additions & 1 deletion question/type/calculated/simpletest/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function make_calculated_question_sum() {

$q->answers = array(
13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0),
14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0),
14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.',
FORMAT_HTML, 0),
17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
);
foreach ($q->answers as $answer) {
Expand Down
28 changes: 2 additions & 26 deletions question/type/calculatedmulti/simpletest/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function make_calculatedmulti_question_sum() {
$q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.';
$q->answers = array(
13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0),
14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0),
14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.',
FORMAT_HTML, 0),
17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
);
$q->qtype = question_bank::get_qtype('calculated');
Expand All @@ -71,28 +72,3 @@ public function make_calculatedmulti_question_sum() {
return $q;
}
}


/**
* Test implementation of {@link qtype_calculated_dataset_loader}. Gets the values
* from an array passed to the constructor, rather than querying the database.
*
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_calculated_test_dataset_loader extends qtype_calculated_dataset_loader{
protected $valuesets;

public function __construct($questionid, array $valuesets) {
parent::__construct($questionid);
$this->valuesets = $valuesets;
}

public function get_number_of_items() {
return count($this->valuesets);
}

public function load_values($itemnumber) {
return $this->valuesets[$itemnumber - 1];
}
}
3 changes: 2 additions & 1 deletion question/type/calculatedsimple/simpletest/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function make_calculatedsimple_question_sum() {

$q->answers = array(
13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0),
14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0),
14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.',
FORMAT_HTML, 0),
17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0),
);
foreach ($q->answers as $answer) {
Expand Down
18 changes: 9 additions & 9 deletions question/type/description/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public function test_description_deferredfeedback_history80() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '1',
);
$qsession = (object) array(
Expand Down Expand Up @@ -248,9 +248,9 @@ public function test_description_deferredfeedback_history70() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '0',
);
$qsession = (object) array(
Expand Down Expand Up @@ -396,9 +396,9 @@ public function test_description_deferredfeedback_history0() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '0',
);
$qsession = (object) array(
Expand Down
12 changes: 6 additions & 6 deletions question/type/essay/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ public function test_essay_deferredfeedback_history820() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '0',
'options' => (object) array(
'answers' => array(
Expand Down Expand Up @@ -516,9 +516,9 @@ public function test_essay_deferredfeedback_missing() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '0',
'options' => (object) array(
'answers' => array(
Expand Down
18 changes: 9 additions & 9 deletions question/type/match/db/simpletest/testupgradelibnewqe.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public function test_match_deferredfeedback_history6220() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '3',
'options' => (object) array(
'id' => '27',
Expand Down Expand Up @@ -352,9 +352,9 @@ public function test_match_deferredfeedback_history60() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '1',
'options' => (object) array(
'id' => '35',
Expand Down Expand Up @@ -563,9 +563,9 @@ public function test_match_deferredfeedback_history622220() {
'generalfeedbackformat' => '1',
'timecreated' => '0',
'timemodified' => '0',
'createdby' => NULL,
'modifiedby' => NULL,
'unlimited' => NULL,
'createdby' => null,
'modifiedby' => null,
'unlimited' => null,
'maxmark' => '1',
'options' => (object) array(
'id' => '279',
Expand Down
Loading

0 comments on commit e073681

Please sign in to comment.