Skip to content

Commit

Permalink
sorting out codechecker errors #520123
Browse files Browse the repository at this point in the history
  • Loading branch information
mkassaei committed May 30, 2024
1 parent 0b6a70f commit cf9bedd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 42 deletions.
12 changes: 6 additions & 6 deletions classes/line.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ class line {
const LINE_NUMBER_ADD = 2;

/** @var string linesegment (Line segment ---). */
const TYPE_LINE_SEGMENT ='linesegment';
const TYPE_LINE_SEGMENT = 'linesegment';

/** @var string linesinglearrow (Single arrow -→). */
const TYPE_LINE_SINGLE_ARROW ='linesinglearrow';
const TYPE_LINE_SINGLE_ARROW = 'linesinglearrow';

/** @var string linedoublearrows (Double arrows ←--→). */
const TYPE_LINE_DOUBLE_ARROW ='linedoublearrows';
const TYPE_LINE_DOUBLE_ARROW = 'linedoublearrows';

/** @var string lineinfinite (Infinite line --o--o--). */
const TYPE_LINE_INFINITE ='lineinfinite';
const TYPE_LINE_INFINITE = 'lineinfinite';


/** @var string lineinfinite (Infinite line --o--o--). */
Expand Down Expand Up @@ -125,11 +125,11 @@ public static function get_line_types(): array {
*/
public static function is_zone_coordinates_valid(string $zone): bool {
preg_match_all(self::VALIDATE_ZONE_COORDINATES, $zone, $matches);
// If the zone is empty return fale
// If the zone is empty return false.
if (trim($zone) === '') {
return false;
}
// if there is no match return false.
// If there is no match return false.
foreach ($matches as $i => $match) {
if (empty($matches[$i])) {
return false;
Expand Down
5 changes: 2 additions & 3 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ class provider implements
// This component has data.
// We need to return default options that have been set a user preferences.
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider
{
\core_privacy\local\request\user_preference_provider {

/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {
$collection->add_user_preference('qtype_drawlines_defaultmark', 'privacy:preference:defaultmark');
$collection->add_user_preference('qtype_drawlines_penalty', 'privacy:preference:penalty');
$collection->add_user_preference('qtype_drawlines_grademethod', 'privacy:preference:grademethod');
Expand Down
11 changes: 3 additions & 8 deletions edit_drawlines_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function data_preprocessing($question) {
self::file_picker_options());
$question->bgimage = $draftitemid;

//$this->js_call();
// TODO: Require js amd module for fom.

return $question;
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public function validation($data, $files) {
if (!$bgimagesize === null) {
$errors["bgimage"] = get_string('formerror_nobgimage', 'qtype_' . $this->qtype());
}
// Validate whether the line type error needed to be displayed.
// Validate whether the line type error needed to be displayed.
for ($i = 0; $i < $this->numberoflines; $i++) {
// Validate line type.
if (!in_array($data["type"][$i], array_keys(line::get_line_types())) &&
Expand Down Expand Up @@ -315,10 +315,5 @@ protected function get_per_line_fields(MoodleQuickForm $mform, string $label, ar
$mform->setType('zoneend', PARAM_RAW_TRIMMED);
return $repeated;
}

//public function js_call() {
// global $PAGE;
// $PAGE->requires->js_call_amd('qtype_drawlines/form', 'init');
//}


}
4 changes: 2 additions & 2 deletions lang/en/qtype_drawlines.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
$string['answer'] = 'Answer';

$string['bgimage'] = 'Background image';
$string['dropbackground'] = 'Background image for dragging markers onto';

//$string['coords'] = 'Coordinates';
$string['correctansweris'] = 'The correct answer is: {$a}';

$string['dropbackground'] = 'Background image for dragging markers onto';

$string['formerror_nobgimage'] = 'You need to select an image to use as the background for the drag and drop area.';
$string['formerror_notype'] = 'You have to select a type for Line {$a}';
$string['formerror_zonestart'] = 'Start zone coordinates should be in x,y;r format, where x,y are the coordinates of the centre of a circle and r is the radius.';
Expand Down
4 changes: 2 additions & 2 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function get_validation_error(array $response) {
public function get_num_parts_right(array $response) {
$chosenhits = $this->choose_hits($response);
$divisor = max(count($this->rightchoices), $this->total_number_of_items_dragged($response));
return array(count($chosenhits), $divisor);
return [count($chosenhits), $divisor];
}

/**
Expand Down Expand Up @@ -218,7 +218,7 @@ public function get_right_choice_for($place) {
public function grade_response(array $response) {
list($right, $total) = $this->get_num_parts_right($response);
$fraction = $right / $total;
return array($fraction, question_state::graded_state_for_fraction($fraction));
return [$fraction, question_state::graded_state_for_fraction($fraction)];
}

public function compute_final_grade($responses, $totaltries) {
Expand Down
9 changes: 3 additions & 6 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public function save_hints($fromform, $withparts = false) {
global $DB;
$context = $fromform->context;

$oldhints = $DB->get_records('question_hints',
array('questionid' => $fromform->id), 'id ASC');
$oldhints = $DB->get_records('question_hints', ['questionid' => $fromform->id], 'id ASC');

if (!empty($fromform->hint)) {
$numhints = max(array_keys($fromform->hint)) + 1;
Expand Down Expand Up @@ -166,7 +165,7 @@ public function save_hints($fromform, $withparts = false) {
$fs = get_file_storage();
foreach ($oldhints as $oldhint) {
$fs->delete_area_files($context->id, 'question', 'hint', $oldhint->id);
$DB->delete_records('question_hints', array('id' => $oldhint->id));
$DB->delete_records('question_hints', ['id' => $oldhint->id]);
}
}

Expand All @@ -178,12 +177,11 @@ protected function make_question_instance($questiondata) {
protected function initialise_question_instance(question_definition $question, $questiondata): void {
parent::initialise_question_instance($question, $questiondata);
$this->initialise_question_lines($question, $questiondata);
//$this->initialise_combined_feedback($question, $questiondata, true);
}

protected function initialise_question_lines(question_definition $question, stdClass $questiondata): void {
foreach ($questiondata->lines as $line) {
$question->lines[$line->number -1] = $this->make_line($line);
$question->lines[$line->number - 1] = $this->make_line($line);
}
}
protected function initialise_combined_feedback(question_definition $question, $questiondata, $withparts = false) {
Expand All @@ -208,7 +206,6 @@ public function delete_question($questionid, $contextid) {
$DB->delete_records('qtype_drawlines_options', ['questionid' => $questionid]);
$DB->delete_records('qtype_drawlines_lines', ['questionid' => $questionid]);
// TODO: user the answer table for storing drag items.
//$DB->delete_records('qtype_drawlines_drags', ['questionid' => $questionid]);
parent::delete_question($questionid, $contextid);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function get_drawlines_question_data_mkmap_twolines(): stdClass {
'labelend' => '',
'zonestart' => '100,100;10',
'zoneend' => '322,213;10',
]
],
];
$qdata->hints = [
1 => (object) [
Expand Down
25 changes: 11 additions & 14 deletions tests/questiontype_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ protected function tearDown(): void {
$this->qtype = null;
}

public function test_name() {
public function test_name(): void {
$this->assertEquals($this->qtype->name(), 'drawlines');
}

public function test_can_analyse_responses() {
public function test_can_analyse_responses(): void {
$this->assertTrue($this->qtype->can_analyse_responses());
}

public function test_make_line() {
public function test_make_line(): void {
$this->resetAfterTest();

$line = new stdClass();
Expand All @@ -75,10 +75,7 @@ public function test_make_line() {
}
}

/**
* Test to make sure that loading of question options works, including in an error case.
*/
public function test_get_question_options() {
public function test_get_question_options(): void {
global $DB;

$this->resetAfterTest(true);
Expand All @@ -102,16 +99,16 @@ public function test_get_question_options() {
$this->assertEquals($formdata->shownumcorrect, $options->shownumcorrect);

foreach ($question->lines as $line) {
$this->assertEquals($line->type, $formdata->type[$line->number -1]);
$this->assertEquals($line->labelstart, $formdata->labelstart[$line->number -1]);
$this->assertEquals($line->labelmiddle, $formdata->labelmiddle[$line->number -1]);
$this->assertEquals($line->labelend, $formdata->labelend[$line->number -1]);
$this->assertEquals($line->zonestart, $formdata->zonestart[$line->number -1]);
$this->assertEquals($line->zoneend, $formdata->zoneend[$line->number -1]);
$this->assertEquals($line->type, $formdata->type[$line->number - 1]);
$this->assertEquals($line->labelstart, $formdata->labelstart[$line->number - 1]);
$this->assertEquals($line->labelmiddle, $formdata->labelmiddle[$line->number - 1]);
$this->assertEquals($line->labelend, $formdata->labelend[$line->number - 1]);
$this->assertEquals($line->zonestart, $formdata->zonestart[$line->number - 1]);
$this->assertEquals($line->zoneend, $formdata->zoneend[$line->number - 1]);
};
}

public function test_save_lines() {
public function test_save_lines(): void {
global $DB;

$this->resetAfterTest(true);
Expand Down

0 comments on commit cf9bedd

Please sign in to comment.