Commit 9c197f44 authored by Tim Hunt's avatar Tim Hunt
Browse files

MDL-20636 Fix some more codechecker issues.

parent bee82469
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -149,10 +148,11 @@ abstract class question_engine {
* @return question_behaviour an instance of appropriate behaviour class.
*/
public static function make_archetypal_behaviour($preferredbehaviour, question_attempt $qa) {
question_engine::load_behaviour_class($preferredbehaviour);
self::load_behaviour_class($preferredbehaviour);
$class = 'qbehaviour_' . $preferredbehaviour;
if (!constant($class . '::IS_ARCHETYPAL')) {
throw new coding_exception('The requested behaviour is not actually an archetypal one.');
throw new coding_exception('The requested behaviour is not actually ' .
'an archetypal one.');
}
return new $class($qa, $preferredbehaviour);
}
......@@ -188,7 +188,7 @@ abstract class question_engine {
try {
self::load_behaviour_class($behaviour);
} catch (Exception $e) {
question_engine::load_behaviour_class('missing');
self::load_behaviour_class('missing');
return new qbehaviour_missing($qa, $preferredbehaviour);
}
$class = 'qbehaviour_' . $behaviour;
......@@ -538,7 +538,8 @@ abstract class question_flags {
* @param object $user the user. If null, defaults to $USER.
* @return string that needs to be sent to question/toggleflag.php for it to work.
*/
protected static function get_toggle_checksum($qubaid, $questionid, $qaid, $slot, $user = null) {
protected static function get_toggle_checksum($qubaid, $questionid,
$qaid, $slot, $user = null) {
if (is_null($user)) {
global $USER;
$user = $USER;
......@@ -577,7 +578,7 @@ abstract class question_flags {
// three ids and the users username. Since we are only updating a flag, that
// probably makes it sufficiently difficult for malicious users to toggle
// other users flags.
if ($checksum != question_flags::get_toggle_checksum($qubaid, $questionid, $qaid, $slot)) {
if ($checksum != self::get_toggle_checksum($qubaid, $questionid, $qaid, $slot)) {
throw new moodle_exception('errorsavingflags', 'question');
}
......@@ -738,14 +739,15 @@ abstract class question_utils {
return ((integer) $value1) === ((integer) $value2);
}
private static $units = array('', 'i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix');
private static $tens = array('', 'x', 'xx', 'xxx', 'xl', 'l', 'lx', 'lxx', 'lxxx', 'xc');
private static $hundreds = array('', 'c', 'cc', 'ccc', 'cd', 'd', 'dc', 'dcc', 'dccc', 'cm');
private static $units = array('', 'i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii', 'viii', 'ix');
private static $tens = array('', 'x', 'xx', 'xxx', 'xl', 'l', 'lx', 'lxx', 'lxxx', 'xc');
private static $hundreds = array('', 'c', 'cc', 'ccc', 'cd', 'd', 'dc', 'dcc', 'dccc', 'cm');
private static $thousands = array('', 'm', 'mm', 'mmm');
/**
* Convert an integer to roman numerals.
* @param int $number an integer between 1 and 3999 inclusive. Anything else will throw an exception.
* @param int $number an integer between 1 and 3999 inclusive. Anything else
* will throw an exception.
* @return string the number converted to lower case roman numerals.
*/
public static function int_to_roman($number) {
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -65,10 +64,16 @@ defined('MOODLE_INTERNAL') || die();
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class question_attempt_step {
/** @var integer if this attempts is stored in the question_attempts table, the id of that row. */
/**
* @var integer if this attempts is stored in the question_attempts table,
* the id of that row.
*/
private $id = null;
/** @var question_state one of the {@link question_state} constants. The state after this step. */
/**
* @var question_state one of the {@link question_state} constants.
* The state after this step.
*/
private $state;
/** @var null|number the fraction (grade on a scale of minfraction .. 1.0) or null. */
......@@ -175,7 +180,8 @@ class question_attempt_step {
*/
public function set_qt_var($name, $value) {
if ($name[0] != '_') {
throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.');
throw new coding_exception('Cannot set question type data ' . $name .
' on an attempt step. You can only set variables with names begining with _.');
}
$this->data[$name] = $value;
}
......@@ -291,7 +297,8 @@ class question_attempt_step {
*/
public function set_behaviour_var($name, $value) {
if ($name[0] != '_') {
throw new coding_exception('Cannot set question type data ' . $name . ' on an attempt step. You can only set variables with names begining with _.');
throw new coding_exception('Cannot set question type data ' . $name .
' on an attempt step. You can only set variables with names begining with _.');
}
return $this->data['-' . $name] = $value;
}
......@@ -351,7 +358,8 @@ class question_attempt_step {
while ($currentrec->attemptstepid != $attemptstepid) {
$currentrec = next($records);
if (!$currentrec) {
throw new coding_exception("Question attempt step $attemptstepid not found in the database.");
throw new coding_exception('Question attempt step ' . $attemptstepid .
' not found in the database.');
}
}
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -210,7 +209,8 @@ class question_usage_by_activity {
*/
protected function check_slot($slot) {
if (!array_key_exists($slot, $this->questionattempts)) {
throw new coding_exception("There is no question_attempt number $slot in this attempt.");
throw new coding_exception('There is no question_attempt number ' . $slot .
' in this attempt.');
}
}
......@@ -361,7 +361,8 @@ class question_usage_by_activity {
*/
public function render_question_at_step($slot, $seq, $options, $number = null) {
$options->context = $this->context;
return $this->get_question_attempt($slot)->render_at_step($seq, $options, $number, $this->preferredbehaviour);
return $this->get_question_attempt($slot)->render_at_step(
$seq, $options, $number, $this->preferredbehaviour);
}
/**
......@@ -374,8 +375,10 @@ class question_usage_by_activity {
* @param bool $forcedownload whether the user must be forced to download the file.
* @return bool true if the user can access this file.
*/
public function check_file_access($slot, $options, $component, $filearea, $args, $forcedownload) {
return $this->get_question_attempt($slot)->check_file_access($options, $component, $filearea, $args, $forcedownload);
public function check_file_access($slot, $options, $component, $filearea,
$args, $forcedownload) {
return $this->get_question_attempt($slot)->check_file_access(
$options, $component, $filearea, $args, $forcedownload);
}
/**
......@@ -681,7 +684,8 @@ class question_attempt_iterator implements Iterator, ArrayAccess {
protected $slots;
/**
* To create an instance of this class, use {@link question_usage_by_activity::get_attempt_iterator()}.
* To create an instance of this class, use
* {@link question_usage_by_activity::get_attempt_iterator()}.
* @param $quba the usage to iterate over.
*/
public function __construct(question_usage_by_activity $quba) {
......@@ -718,10 +722,12 @@ class question_attempt_iterator implements Iterator, ArrayAccess {
return $this->quba->get_question_attempt($slot);
}
public function offsetSet($slot, $value) {
throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot set.');
throw new coding_exception('You are only allowed read-only access to ' .
'question_attempt::states through a question_attempt_step_iterator. Cannot set.');
}
public function offsetUnset($slot) {
throw new coding_exception('You are only allowed read-only access to question_attempt::states through a question_attempt_step_iterator. Cannot unset.');
throw new coding_exception('You are only allowed read-only access to ' .
'question_attempt::states through a question_attempt_step_iterator. Cannot unset.');
}
}
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -160,7 +159,8 @@ class core_question_renderer extends plugin_renderer_base {
* @param question_display_options $options controls what should and should not be displayed.
* @return HTML fragment.
*/
protected function status(question_attempt $qa, qbehaviour_renderer $behaviouroutput, question_display_options $options) {
protected function status(question_attempt $qa, qbehaviour_renderer $behaviouroutput,
question_display_options $options) {
return html_writer::tag('div', $qa->get_state_string($options->correctness),
array('class' => 'state'));
}
......@@ -181,7 +181,8 @@ class core_question_renderer extends plugin_renderer_base {
} else if ($options->marks == question_display_options::MAX_ONLY ||
is_null($qa->get_fraction())) {
$summary = get_string('markedoutofmax', 'question', $qa->format_max_mark($options->markdp));
$summary = get_string('markedoutofmax', 'question',
$qa->format_max_mark($options->markdp));
} else {
$a = new stdClass();
......@@ -213,13 +214,17 @@ class core_question_renderer extends plugin_renderer_base {
$checked = '';
}
$postdata = question_flags::get_postdata($qa);
// The checkbox id must be different from any element name, becuase
// of a stupid IE bug: http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/
// The checkbox id must be different from any element name, because
// of a stupid IE bug:
// http://www.456bereastreet.com/archive/200802/beware_of_id_and_name_attribute_mixups_when_using_getelementbyid_in_internet_explorer/
$flagcontent = '<input type="hidden" name="' . $id . '" value="0" />' .
'<input type="checkbox" id="' . $id . 'checkbox" name="' . $id . '" value="1" ' . $checked . ' />' .
'<input type="hidden" value="' . s($postdata) . '" class="questionflagpostdata" />' .
'<label id="' . $id . 'label" for="' . $id . 'checkbox">' . $this->get_flag_html(
$qa->is_flagged(), $id . 'img') . '</label>' . "\n";
'<input type="checkbox" id="' . $id . 'checkbox" name="' . $id .
'" value="1" ' . $checked . ' />' .
'<input type="hidden" value="' . s($postdata) .
'" class="questionflagpostdata" />' .
'<label id="' . $id . 'label" for="' . $id . 'checkbox">' .
$this->get_flag_html($qa->is_flagged(), $id . 'img') .
'</label>' . "\n";
break;
default:
$flagcontent = '';
......@@ -343,9 +348,11 @@ class core_question_renderer extends plugin_renderer_base {
if ($stepno == $qa->get_num_steps()) {
$rowclass = 'current';
} else if (!empty($options->questionreviewlink)) {
$url = new moodle_url($options->questionreviewlink, array('slot' => $qa->get_slot(), 'step' => $i));
$url = new moodle_url($options->questionreviewlink,
array('slot' => $qa->get_slot(), 'step' => $i));
$stepno = $this->output->action_link($url, $stepno,
new popup_action('click', $url, 'reviewquestion', array('width' => 450, 'height' => 650)),
new popup_action('click', $url, 'reviewquestion',
array('width' => 450, 'height' => 650)),
array('title' => get_string('reviewresponse', 'question')));
}
$user = new stdClass();
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -37,7 +36,7 @@ require_once(dirname(__FILE__) . '/../lib.php');
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_question_attempt extends question_attempt {
public function add_step($step) {#
public function add_step($step) {
parent::add_step($step);
}
public function set_min_fraction($fraction) {
......@@ -74,7 +73,8 @@ abstract class question_test_helper {
*/
class test_question_maker {
const STANDARD_OVERALL_CORRECT_FEEDBACK = 'Well done!';
const STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK = 'Parts, but only parts, of your response are correct.';
const STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK =
'Parts, but only parts, of your response are correct.';
const STANDARD_OVERALL_INCORRECT_FEEDBACK = 'That is not right at all.';
/** @var array qtype => qtype test helper class. */
......@@ -329,8 +329,10 @@ class test_question_maker {
$description = new qtype_description_question();
self::initialise_a_question($description);
$description->name = 'Description question';
$description->questiontext = 'This text tells you a bit about the next few questions in this quiz.';
$description->generalfeedback = 'This is what this section of the quiz should have taught you.';
$description->questiontext =
'This text tells you a bit about the next few questions in this quiz.';
$description->generalfeedback =
'This is what this section of the quiz should have taught you.';
$description->qtype = question_bank::get_qtype('description');
return $description;
......@@ -419,7 +421,8 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
$this->quba = null;
}
protected function start_attempt_at_question($question, $preferredbehaviour, $maxmark = null) {
protected function start_attempt_at_question($question, $preferredbehaviour,
$maxmark = null) {
$this->quba->set_preferred_behaviour($preferredbehaviour);
$this->slot = $this->quba->add_question($question, $maxmark);
$this->quba->start_all_questions();
......@@ -433,7 +436,8 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
}
protected function check_current_state($state) {
$this->assertEqual($this->quba->get_question_state($this->slot), $state, 'Questions is in the wrong state: %s.');
$this->assertEqual($this->quba->get_question_state($this->slot), $state,
'Questions is in the wrong state: %s.');
}
protected function check_current_mark($mark) {
......@@ -493,7 +497,8 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
}
protected function get_contains_partcorrect_expectation() {
return new PatternExpectation('/' . preg_quote(get_string('partiallycorrect', 'question')) . '/');
return new PatternExpectation('/' .
preg_quote(get_string('partiallycorrect', 'question')) . '/');
}
protected function get_contains_incorrect_expectation() {
......@@ -501,15 +506,18 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
}
protected function get_contains_standard_correct_combined_feedback_expectation() {
return new PatternExpectation('/' . preg_quote(test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK) . '/');
return new PatternExpectation('/' .
preg_quote(test_question_maker::STANDARD_OVERALL_CORRECT_FEEDBACK) . '/');
}
protected function get_contains_standard_partiallycorrect_combined_feedback_expectation() {
return new PatternExpectation('/' . preg_quote(test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK) . '/');
return new PatternExpectation('/' .
preg_quote(test_question_maker::STANDARD_OVERALL_PARTIALLYCORRECT_FEEDBACK) . '/');
}
protected function get_contains_standard_incorrect_combined_feedback_expectation() {
return new PatternExpectation('/' . preg_quote(test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK) . '/');
return new PatternExpectation('/' .
preg_quote(test_question_maker::STANDARD_OVERALL_INCORRECT_FEEDBACK) . '/');
}
protected function get_does_not_contain_feedback_expectation() {
......@@ -576,7 +584,8 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
return new ContainsTagWithAttributes('input', $expectedattributes, $forbiddenattributes);
}
protected function get_contains_mc_checkbox_expectation($index, $enabled = null, $checked = null) {
protected function get_contains_mc_checkbox_expectation($index, $enabled = null,
$checked = null) {
return $this->get_contains_checkbox_expectation(array(
'name' => $this->quba->get_field_prefix($this->slot) . $index,
'value' => 1,
......@@ -637,7 +646,8 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
), $enabled, $checked);
}
protected function get_contains_cbm_radio_expectation($certainty, $enabled = null, $checked = null) {
protected function get_contains_cbm_radio_expectation($certainty, $enabled = null,
$checked = null) {
return $this->get_contains_radio_expectation(array(
'name' => $this->quba->get_field_prefix($this->slot) . '-certainty',
'value' => $certainty,
......@@ -667,11 +677,13 @@ class qbehaviour_walkthrough_test_base extends UnitTestCase {
}
protected function get_tries_remaining_expectation($n) {
return new PatternExpectation('/' . preg_quote(get_string('triesremaining', 'qbehaviour_interactive', $n)) . '/');
return new PatternExpectation('/' .
preg_quote(get_string('triesremaining', 'qbehaviour_interactive', $n)) . '/');
}
protected function get_invalid_answer_expectation() {
return new PatternExpectation('/' . preg_quote(get_string('invalidanswer', 'question')) . '/');
return new PatternExpectation('/' .
preg_quote(get_string('invalidanswer', 'question')) . '/');
}
protected function get_contains_try_again_button_expectation($enabled = null) {
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......@@ -50,7 +49,8 @@ class qubaid_condition_test extends UnitTestCase {
$this->assertEqual($expectedparams, $params);
}
protected function check_typical_in_query(qubaid_condition $qubaids, $expectedsql, $expectedparams) {
protected function check_typical_in_query(qubaid_condition $qubaids,
$expectedsql, $expectedparams) {
$sql = "SELECT qa.id, qa.maxmark
FROM {question_attempts} qa
WHERE qa.questionusageid {$qubaids->usage_id_in()}";
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
......
......@@ -61,8 +61,8 @@ class question_engine_assumption_logger {
$quizattemptid = $this->attemptid;
}
if ($quizattemptid) {
$message .= ' (<a href="' . $CFG->wwwroot . '/mod/quiz/review.php?attempt=' .
$quizattemptid . '">Review this attempt</a>)';
$message .= ' (<a href="' . $CFG->wwwroot . '/mod/quiz/review.php?attempt=' .
$quizattemptid . '">Review this attempt</a>)';
}
$message .= "</p>\n";
fwrite($this->handle, $message);
......
......@@ -80,7 +80,7 @@ class test_question_engine_upgrade_question_loader extends question_engine_upgra
}
public function load_question($questionid, $quizid) {
global $CFG, $QTYPES;
global $CFG;
if (isset($this->cache[$questionid])) {
return $this->cache[$questionid];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment