Skip to content

Commit

Permalink
Fix CI workflow and code checker errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi committed Oct 20, 2023
1 parent a39bfd1 commit 7bef6ec
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail.
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

Expand Down
4 changes: 2 additions & 2 deletions classes/column.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function __construct(int $questionid, int $number = 0, string $name = '',
* @param array $columns
* @return array
*/
static public function get_column_ids(array $columns): array {
public static function get_column_ids(array $columns): array {
$columnids = [];
foreach($columns as $column) {
foreach ($columns as $column) {
$columnids[$column->id] = $column;
}
return $columnids;
Expand Down
7 changes: 2 additions & 5 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
use core_privacy\local\request\transform;
use core_privacy\local\request\writer;

defined('MOODLE_INTERNAL') || die();

/**
* Privacy Subsystem for qtype_oumatrix implementing user_preference_provider.
*
Expand All @@ -40,8 +38,7 @@ 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.
Expand Down Expand Up @@ -94,4 +91,4 @@ public static function export_user_preferences(int $userid) {
writer::export_user_preference('qtype_oumatrix', 'shuffleanswers', transform::yesno($preference), $desc);
}
}
}
}
11 changes: 2 additions & 9 deletions edit_oumatrix_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ private function data_preprocessing_columns($question) {
return $question;
}
$question->columnname = [];
/**
* @var column $column
*/
foreach ($question->columns as $column) {
foreach ($question->columns as $column) { // Class column $column.
if (trim($column->name ?? '') === '') {
continue;
}
Expand All @@ -261,11 +258,7 @@ private function data_preprocessing_rows($question) {
}
$key = 0;
$question->rowname = [];
/**
* @var int $index
* @var row $row
*/
foreach ($question->rows as $index => $row) {
foreach ($question->rows as $index => $row) { // Key int $index, class row $row.
$question->rowname[$row->number - 1] = $row->name;
$decodedanswers = json_decode($row->correctanswers, true);
foreach ($question->columns as $key => $column) {
Expand Down
6 changes: 4 additions & 2 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use qtype_oumatrix\column;
use qtype_oumatrix\row;

defined('MOODLE_INTERNAL') || die();

/**
* Class that represents an oumatrix question.
*
Expand Down Expand Up @@ -180,7 +182,7 @@ public function is_choice_selected($response, $rowkey, $colkey) {
}

public function prepare_simulated_post_data($simulatedresponse) {
return $simulatedresponse; // TODO
return $simulatedresponse; // TODO.
}

public function is_same_response(array $prevresponse, array $newresponse): bool {
Expand Down Expand Up @@ -305,7 +307,7 @@ protected function field(int $rowkey, int $columnkey): string {
}

public function prepare_simulated_post_data($simulatedresponse) {
return $simulatedresponse; // TODO
return $simulatedresponse; // TODO.
}

public function is_same_response(array $prevresponse, array $newresponse): bool {
Expand Down
19 changes: 10 additions & 9 deletions questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ public function get_random_guess_score($questiondata) {
* @return int
*/
public function get_total_number_of_choices(object $questiondata):? int {
// if rows or columns are not set return null;
if (sizeof($questiondata->columns) === 0 || sizeof($questiondata->rows) === 0) {
// If rows or columns are not set return null.
if (count($questiondata->columns) === 0 || count($questiondata->rows) === 0) {
return null;
}
// Total number of choices for each row is the number of columns,
// therefore the total number of choices for the question is
// therefore the total number of choices for the question is.
return count($questiondata->columns) * count($questiondata->rows);
}

Expand All @@ -292,7 +292,7 @@ public function get_num_correct_choices($questiondata) {

public function get_possible_responses($questiondata) {
if ($questiondata->options->single) {
$responses = array();
$responses = [];

// TODO: Sort out this funtion to work with rows and columns, etc.
foreach ($questiondata->options->answers as $aid => $answer) {
Expand All @@ -302,14 +302,15 @@ public function get_possible_responses($questiondata) {
}

$responses[null] = question_possible_response::no_response();
return array($questiondata->id => $responses);
return [$questiondata->id => $responses];
} else {
$parts = array();
$parts = [];

foreach ($questiondata->options->answers as $aid => $answer) {
$parts[$aid] = array($aid => new question_possible_response(
question_utils::to_plain_text($answer->answer, $answer->answerformat),
$answer->fraction));
$parts[$aid] = [
$aid => new question_possible_response(question_utils::to_plain_text(
$answer->answer, $answer->answerformat), $answer->fraction),
];
}

return $parts;
Expand Down
2 changes: 2 additions & 0 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

use qtype_oumatrix\column;

defined('MOODLE_INTERNAL') || die();

/**
* Base class for generating the bits of output common to oumatrix
* single choice and multiple response questions.
Expand Down
6 changes: 3 additions & 3 deletions tests/edit_oumatrix_form_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @package qtype_oumatrix
* @copyright 2023 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \qtype_oumatrix_edit_form
*/

/**
Expand All @@ -43,6 +42,7 @@
* @package qtype_oumatrix
* @copyright 2023 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \qtype_oumatrix_edit_form
*/
class edit_oumatrix_form_test extends \advanced_testcase {

Expand All @@ -59,15 +59,15 @@ protected function get_form($classname) {
$this->setAdminUser();
$this->resetAfterTest();
$syscontext = \context_system::instance();
$category = question_make_default_categories(array($syscontext));
$category = question_make_default_categories([$syscontext]);
$fakequestion = new stdClass();
$fakequestion->qtype = 'oumatrix';
$fakequestion->contextid = $syscontext->id;
$fakequestion->createdby = 2;
$fakequestion->category = $category->id;
$fakequestion->questiontext = 'Animal classification. Please answer the sub questions in all 4 rows.';
$fakequestion->options = new stdClass();
$fakequestion->options->answers = array();
$fakequestion->options->answers = [];
$fakequestion->formoptions = new stdClass();
$fakequestion->formoptions->movecontext = null;
$fakequestion->formoptions->repeatelements = true;
Expand Down
6 changes: 3 additions & 3 deletions tests/questiontype_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function test_name() {
$this->assertEquals($this->qtype->name(), 'oumatrix');
}

public function TODO_test_initialise_question_instance() {
public function todo_test_initialise_question_instance() {
$h = new qtype_oumatrix_test_helper();
$qdata = $h->get_test_question_data('animals_single');
$expected = $h->get_test_question_data('animals_single');
Expand Down Expand Up @@ -94,7 +94,7 @@ public function get_save_question_which() {
* @dataProvider get_save_question_which
* @param $which
*/
public function TODO_test_save_question() {
public function todo_test_save_question() {
$this->resetAfterTest(true);
$this->setAdminUser();

Expand Down Expand Up @@ -156,7 +156,7 @@ public function TODO_test_save_question() {
/**
* Test to make sure that loading of question options works, including in an error case.
*/
public function TODO_test_get_question_options() {
public function todo_test_get_question_options() {
global $DB;

$this->resetAfterTest(true);
Expand Down

0 comments on commit 7bef6ec

Please sign in to comment.