Skip to content

Commit 496335e

Browse files
committed
Make Moodle codechecker happy.
1 parent bf385c9 commit 496335e

24 files changed

+147
-23
lines changed

classes/admin/question_behaviour_setting.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3030
*/
3131
class question_behaviour_setting extends \admin_setting_configselect {
32+
33+
/**
34+
* Load the choices.
35+
*
36+
* @return true
37+
*/
3238
public function load_choices() {
3339
if (is_array($this->choices)) {
3440
return true;

classes/attempt.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public function setup_usage_info(\question_usage_by_activity $quba, int $slot) {
205205
* @param \question_usage_by_activity|null $quba usage to use. If null will continue using the same usage.
206206
*/
207207
public function start_new_attempt_at_question(
208-
\question_usage_by_activity $quba = null) {
208+
?\question_usage_by_activity $quba = null) {
209209
global $DB;
210210

211211
if ($quba) {
@@ -386,7 +386,7 @@ public function get_problem_description(): string {
386386
* @param array $simulatedpostdata for testing, simulated post data (e.g. from
387387
* $quba->get_simulated_post_data_for_questions_in_usage()).
388388
*/
389-
public function process_submitted_actions(array $simulatedpostdata = null) {
389+
public function process_submitted_actions(?array $simulatedpostdata = null) {
390390
global $DB;
391391

392392
$this->quba->process_all_actions(null, $simulatedpostdata);

classes/custom_string_manager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public static function force_page_language($lang) {
4242
get_string_manager(true)->forcedlanguage = $lang;
4343
}
4444

45+
/**
46+
* Get String returns a requested string
47+
*
48+
* @param string $identifier The identifier of the string to search for
49+
* @param string $component The module the string is associated with
50+
* @param string|object|array $a An object, string or number that can be used
51+
* within translation strings
52+
* @param string $lang moodle translation language, null means use current
53+
* @return string The String !
54+
*/
4555
public function get_string($identifier, $component = '', $a = null, $lang = null) {
4656
return parent::get_string($identifier, $component, $a, $lang ?? $this->forcedlanguage);
4757
}

classes/event/category_token_created.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,30 @@
2929
*/
3030
class category_token_created extends \core\event\base {
3131

32+
/**
33+
* Init method.
34+
*/
3235
protected function init() {
3336
$this->data['objecttable'] = 'question_categories';
3437
$this->data['crud'] = 'c';
3538
$this->data['edulevel'] = self::LEVEL_TEACHING;
3639
}
3740

41+
/**
42+
* Returns non-localised description of what happened.
43+
*
44+
* @return string
45+
*/
3846
public function get_description() {
3947
return "The user with id '$this->userid' created a token for embedded a question " .
4048
"picked at random from category '$this->objectid' in course '$this->courseid'.";
4149
}
4250

51+
/**
52+
* Get objectid mapping.
53+
*
54+
* @return array
55+
*/
4356
public static function get_objectid_mapping() {
4457
return ['db' => 'question_categories', 'restore' => 'question_categories'];
4558
}

classes/event/question_attempted.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,30 @@
2929
*/
3030
class question_attempted extends \core\event\base {
3131

32+
/**
33+
* Init method.
34+
*/
3235
protected function init() {
3336
$this->data['objecttable'] = 'question';
3437
$this->data['crud'] = 'u';
3538
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
3639
}
3740

41+
/**
42+
* Returns non-localised description of what happened.
43+
*
44+
* @return string
45+
*/
3846
public function get_description() {
3947
return "The user with id '$this->userid' has submitted data to the embedded question " .
4048
"'$this->objectid' in course '$this->courseid'.";
4149
}
4250

51+
/**
52+
* Get objectid mapping.
53+
*
54+
* @return array
55+
*/
4356
public static function get_objectid_mapping() {
4457
return ['db' => 'question', 'restore' => 'question'];
4558
}

classes/event/question_started.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,30 @@
2929
*/
3030
class question_started extends \core\event\base {
3131

32+
/**
33+
* Init method.
34+
*/
3235
protected function init() {
3336
$this->data['objecttable'] = 'question';
3437
$this->data['crud'] = 'c';
3538
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
3639
}
3740

41+
/**
42+
* Returns non-localised description of what happened.
43+
*
44+
* @return string
45+
*/
3846
public function get_description() {
3947
return "The user with id '$this->userid' has started an attempt at embedded question " .
4048
"'$this->objectid' in course '$this->courseid'.";
4149
}
4250

51+
/**
52+
* Get objectid mapping.
53+
*
54+
* @return array
55+
*/
4356
public static function get_objectid_mapping() {
4457
return ['db' => 'question', 'restore' => 'question'];
4558
}

classes/event/question_viewed.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,30 @@
2929
*/
3030
class question_viewed extends \core\event\base {
3131

32+
/**
33+
* Init method.
34+
*/
3235
protected function init() {
3336
$this->data['objecttable'] = 'question';
3437
$this->data['crud'] = 'r';
3538
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
3639
}
3740

41+
/**
42+
* Returns non-localised description of what happened.
43+
*
44+
* @return string
45+
*/
3846
public function get_description() {
3947
return "The user with id '$this->userid' has viewed the embedded question " .
4048
"'$this->objectid' in course '$this->courseid'.";
4149
}
4250

51+
/**
52+
* Get objectid mapping.
53+
*
54+
* @return array
55+
*/
4356
public static function get_objectid_mapping() {
4457
return ['db' => 'question', 'restore' => 'question'];
4558
}

classes/event/token_created.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,30 @@
2929
*/
3030
class token_created extends \core\event\base {
3131

32+
/**
33+
* Init method.
34+
*/
3235
protected function init() {
3336
$this->data['objecttable'] = 'question';
3437
$this->data['crud'] = 'c';
3538
$this->data['edulevel'] = self::LEVEL_TEACHING;
3639
}
3740

41+
/**
42+
* Returns non-localised description of what happened.
43+
*
44+
* @return string
45+
*/
3846
public function get_description() {
3947
return "The user with id '$this->userid' created a token for embedded question " .
4048
"'$this->objectid' in course '$this->courseid'.";
4149
}
4250

51+
/**
52+
* Get objectid mapping.
53+
*
54+
* @return array
55+
*/
4356
public static function get_objectid_mapping() {
4457
return ['db' => 'question', 'restore' => 'question'];
4558
}

classes/form/embed_options_form.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3939
*/
4040
class embed_options_form extends \moodleform {
41+
42+
/**
43+
* {inheritDocs}
44+
*/
4145
public function definition() {
4246
global $PAGE;
4347

@@ -158,6 +162,9 @@ protected function get_marks_options(int $default): array {
158162
return ['' => get_string('defaultx', 'filter_embedquestion', $options[$default])] + $options;
159163
}
160164

165+
/**
166+
* {inheritDocs}
167+
*/
161168
public function definition_after_data() {
162169
parent::definition_after_data();
163170
$mform = $this->_form;
@@ -199,6 +206,9 @@ protected function get_user_retriction(): ?int {
199206
}
200207
}
201208

209+
/**
210+
* {inheritDocs}
211+
*/
202212
public function validation($data, $files) {
203213
$errors = parent::validation($data, $files);
204214
$context = $this->_customdata['context'];
@@ -235,6 +245,9 @@ public function validation($data, $files) {
235245
return $errors;
236246
}
237247

248+
/**
249+
* {inheritDocs}
250+
*/
238251
public function get_data() {
239252
$data = parent::get_data();
240253

classes/output/embed_iframe.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public function __construct(\moodle_url $showquestionurl, string $iframedescript
4444
$this->iframedescription = $iframedescription;
4545
}
4646

47+
/**
48+
* Export this data so it can be used as the context for a mustache template.
49+
*
50+
* @param renderer_base $output
51+
* @return stdClass
52+
*/
4753
public function export_for_template(renderer_base $output) {
4854
$data = [
4955
'showquestionurl' => $this->showquestionurl,

classes/output/error_message.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public function __construct(string $message) {
3838
$this->message = $message;
3939
}
4040

41+
/**
42+
* Export this data so it can be used as the context for a mustache template.
43+
*
44+
* @param renderer_base $output
45+
* @return stdClass
46+
*/
4147
public function export_for_template(renderer_base $output) {
4248
return ['message' => $this->message];
4349
}

classes/output/renderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* @copyright 2018 The Open University
2727
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2828
*
29-
* @method string header() inherited from core_renderer.
30-
* @method string footer() inherited from core_renderer.
29+
* Method string header() inherited from core_renderer.
30+
* Method string footer() inherited from core_renderer.
3131
*/
3232
class renderer extends \plugin_renderer_base {
3333
/**

classes/privacy/provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
3131
*
3232
* @return string
3333
*/
34-
public static function get_reason() : string {
34+
public static function get_reason(): string {
3535
return 'privacy:metadata';
3636
}
3737
}

classes/task/cleanup_task.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ class cleanup_task extends scheduled_task {
3737
*/
3838
const MAX_AGE = 24 * 60 * 60;
3939

40+
/**
41+
* Get a descriptive name for this task (shown to admins).
42+
*
43+
* @return string
44+
*/
4045
public function get_name() {
4146
return get_string('taskcleanup', 'filter_embedquestion');
4247
}
4348

49+
/**
50+
* Do the job.
51+
* Throw exceptions on errors (the job will be retried).
52+
*/
4453
public function execute() {
4554
$lastmodifiedcutoff = time() - self::MAX_AGE;
4655

classes/text_filter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class text_filter extends \core_filters\text_filter {
5656
*/
5757
protected $page;
5858

59+
/**
60+
* {inheritDocs}
61+
*/
5962
public function setup($page, $context) {
6063
$this->page = $page;
6164
}
@@ -71,6 +74,9 @@ public static function get_filter_regexp(): string {
7174
preg_quote(self::STRING_SUFFIX, '~') . '~';
7275
}
7376

77+
/**
78+
* {inheritDocs}
79+
*/
7480
public function filter($text, array $options = []) {
7581
return preg_replace_callback(self::get_filter_regexp(),
7682
[$this, 'embed_question_callback'], $text);
@@ -131,7 +137,7 @@ public function embed_question(string $embedcode): string {
131137
*
132138
* @return string HTML for the error.
133139
*/
134-
protected function display_error(string $string, array $a = null): string {
140+
protected function display_error(string $string, ?array $a = null): string {
135141
return $this->renderer->render(new error_message(
136142
get_string($string, 'filter_embedquestion', $a)));
137143
}

classes/utils.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public static function is_latest_version(\question_definition $question): bool {
232232
* @param int|null $userid (optional) if set, only count questions created by this user.
233233
* @return array category idnumber => Category name (question count).
234234
*/
235-
public static function get_categories_with_sharable_question_choices(\context $context, int $userid = null): array {
235+
public static function get_categories_with_sharable_question_choices(\context $context, ?int $userid = null): array {
236236
global $DB;
237237

238238
if (self::has_question_versionning()) {
@@ -312,7 +312,7 @@ public static function get_categories_with_sharable_question_choices(\context $c
312312
* @param int|null $userid (optional) if set, only count questions created by this user.
313313
* @return \stdClass[] question id => object with fields question id, name and idnumber.
314314
*/
315-
public static function get_sharable_question_ids(int $categoryid, int $userid = null): array {
315+
public static function get_sharable_question_ids(int $categoryid, ?int $userid = null): array {
316316
global $DB;
317317

318318
if (self::has_question_versionning()) {
@@ -380,7 +380,7 @@ public static function get_sharable_question_ids(int $categoryid, int $userid =
380380
* @param int|null $userid (optional) if set, only count questions created by this user.
381381
* @return array question idnumber => question name.
382382
*/
383-
public static function get_sharable_question_choices(int $categoryid, int $userid = null): array {
383+
public static function get_sharable_question_choices(int $categoryid, ?int $userid = null): array {
384384
$questions = self::get_sharable_question_ids($categoryid, $userid);
385385

386386
$choices = ['' => get_string('choosedots')];

lang/en/filter_embedquestion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
$string['errormaxmarknumber'] = 'The maximum mark must be a number.';
4040
$string['errornopermissions'] = 'You do not have permission to embed this question.';
4141
$string['errorunknownquestion'] = 'Unknown, or unsharable question.';
42-
$string['errorvariantoutofrange'] = 'Variant number must be a positive integer at most {$a}.';
4342
$string['errorvariantformat'] = 'Variant number must be a positive integer.';
43+
$string['errorvariantoutofrange'] = 'Variant number must be a positive integer at most {$a}.';
4444
$string['filtername'] = 'Embed questions';
4545
$string['generalfeedback_desc'] = 'Whether the general feedback should be shown by default in embedded questions.';
4646
$string['howquestionbehaves'] = 'How the question behaves';

tests/attempt_test.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17-
1817
namespace filter_embedquestion;
1918

2019
/**
@@ -26,7 +25,7 @@
2625
* @covers \filter_embedquestion\attempt
2726
* @covers \filter_embedquestion\attempt_storage
2827
*/
29-
class attempt_test extends \advanced_testcase {
28+
final class attempt_test extends \advanced_testcase {
3029

3130
public function test_start_new_attempt_at_question_will_select_an_unused_question(): void {
3231
global $DB, $USER;

0 commit comments

Comments
 (0)