Skip to content

Commit 6a1577d

Browse files
allanhaggettclaude
andcommitted
Fix Moodle coding standards violations
Run phpcbf auto-fixes and manually resolve remaining issues: - Use short array syntax and trailing commas throughout - Replace global $PAGE with $this->page in block class - Add missing class and function docblocks - End all inline comments with full stops - Remove unnecessary MOODLE_INTERNAL checks in namespaced/pure files - Fix trailing whitespace in SQL strings - Break long lines to stay within 132 character limit All files now pass phpcs --standard=moodle --max-warnings 0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5de5cf7 commit 6a1577d

File tree

8 files changed

+287
-259
lines changed

8 files changed

+287
-259
lines changed

block_course_search.php

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626

2727
require_once($CFG->dirroot . '/blocks/moodleblock.class.php');
2828

29+
/**
30+
* Course search block class.
31+
*
32+
* @package block_course_search
33+
* @copyright 2025 Your Name
34+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35+
*/
2936
class block_course_search extends block_base {
30-
3137
/**
3238
* Initialize the block.
3339
*/
@@ -41,58 +47,58 @@ public function init() {
4147
* @return stdClass The block content.
4248
*/
4349
public function get_content() {
44-
global $CFG, $PAGE;
45-
4650
if ($this->content !== null) {
4751
return $this->content;
4852
}
4953

50-
$this->content = new stdClass;
54+
$this->content = new stdClass();
5155
$this->content->text = '';
5256
$this->content->footer = '';
5357

5458
// Only show within a course (course pages and activity pages).
55-
$courseid = $PAGE->course->id;
59+
$courseid = $this->page->course->id;
5660
if (empty($courseid) || $courseid == SITEID) {
5761
return $this->content;
5862
}
59-
60-
// Build the search form
61-
$searchurl = new moodle_url('/blocks/course_search/search.php', array('courseid' => $courseid));
62-
63-
$this->content->text = html_writer::start_tag('form', array(
63+
64+
// Build the search form.
65+
$searchurl = new moodle_url('/blocks/course_search/search.php', ['courseid' => $courseid]);
66+
67+
$this->content->text = html_writer::start_tag('form', [
6468
'method' => 'get',
6569
'action' => $searchurl->out(),
66-
'role' => 'search'
67-
));
68-
69-
$this->content->text .= html_writer::start_tag('div', array('class' => 'course-search-form'));
70-
71-
$this->content->text .= html_writer::tag('label',
72-
get_string('searchcourse', 'block_course_search'),
73-
array('for' => 'course-search-input', 'class' => 'sr-only')
70+
'role' => 'search',
71+
]);
72+
73+
$this->content->text .= html_writer::start_tag('div', ['class' => 'course-search-form']);
74+
75+
$this->content->text .= html_writer::tag(
76+
'label',
77+
get_string('searchcourse', 'block_course_search'),
78+
['for' => 'course-search-input', 'class' => 'sr-only']
7479
);
75-
76-
$this->content->text .= html_writer::empty_tag('input', array(
80+
81+
$this->content->text .= html_writer::empty_tag('input', [
7782
'type' => 'text',
7883
'name' => 'q',
7984
'id' => 'course-search-input',
8085
'placeholder' => get_string('searchcourse', 'block_course_search'),
8186
'class' => 'form-control',
82-
'required' => 'required'
83-
));
84-
85-
$this->content->text .= html_writer::empty_tag('input', array(
87+
'required' => 'required',
88+
]);
89+
90+
$this->content->text .= html_writer::empty_tag('input', [
8691
'type' => 'hidden',
8792
'name' => 'courseid',
88-
'value' => $courseid
89-
));
90-
91-
$this->content->text .= html_writer::tag('button',
92-
get_string('search', 'block_course_search'),
93-
array('type' => 'submit', 'class' => 'btn btn-primary mt-2')
93+
'value' => $courseid,
94+
]);
95+
96+
$this->content->text .= html_writer::tag(
97+
'button',
98+
get_string('search', 'block_course_search'),
99+
['type' => 'submit', 'class' => 'btn btn-primary mt-2']
94100
);
95-
101+
96102
$this->content->text .= html_writer::end_tag('div');
97103
$this->content->text .= html_writer::end_tag('form');
98104

@@ -105,11 +111,11 @@ public function get_content() {
105111
* @return array
106112
*/
107113
public function applicable_formats() {
108-
return array(
114+
return [
109115
'course-view' => true,
110116
'mod' => true,
111-
'all' => false
112-
);
117+
'all' => false,
118+
];
113119
}
114120

115121
/**
@@ -137,4 +143,4 @@ public function instance_create() {
137143
public function instance_allow_multiple() {
138144
return false;
139145
}
140-
}
146+
}

classes/privacy/provider.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@
2424

2525
namespace block_course_search\privacy;
2626

27-
defined('MOODLE_INTERNAL') || die();
28-
2927
/**
3028
* Privacy provider for course search block.
3129
*/
3230
class provider implements \core_privacy\local\metadata\null_provider {
33-
3431
/**
3532
* Get the language string identifier with the component's language
3633
* file to explain why this plugin stores no data.
3734
*
3835
* @return string
3936
*/
40-
public static function get_reason() : string {
37+
public static function get_reason(): string {
4138
return 'privacy:metadata';
4239
}
43-
}
40+
}

db/access.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@
2424

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

27-
$capabilities = array(
28-
'block/course_search:myaddinstance' => array(
27+
$capabilities = [
28+
'block/course_search:myaddinstance' => [
2929
'captype' => 'write',
3030
'contextlevel' => CONTEXT_SYSTEM,
31-
'archetypes' => array(
32-
'user' => CAP_ALLOW
33-
),
34-
'clonepermissionsfrom' => 'moodle/my:manageblocks'
35-
),
31+
'archetypes' => [
32+
'user' => CAP_ALLOW,
33+
],
34+
'clonepermissionsfrom' => 'moodle/my:manageblocks',
35+
],
3636

37-
'block/course_search:addinstance' => array(
37+
'block/course_search:addinstance' => [
3838
'riskbitmask' => RISK_SPAM | RISK_XSS,
3939
'captype' => 'write',
4040
'contextlevel' => CONTEXT_BLOCK,
41-
'archetypes' => array(
41+
'archetypes' => [
4242
'editingteacher' => CAP_ALLOW,
43-
'manager' => CAP_ALLOW
44-
),
45-
'clonepermissionsfrom' => 'moodle/site:manageblocks'
46-
),
47-
);
43+
'manager' => CAP_ALLOW,
44+
],
45+
'clonepermissionsfrom' => 'moodle/site:manageblocks',
46+
],
47+
];

db/upgrade.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,37 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25-
defined('MOODLE_INTERNAL') || die();
26-
25+
/**
26+
* Upgrade the block_course_search plugin.
27+
*
28+
* @param int $oldversion The old version of the plugin.
29+
* @return bool
30+
*/
2731
function xmldb_block_course_search_upgrade($oldversion) {
2832
global $DB;
2933

3034
if ($oldversion < 2025070901) {
3135
// Update existing block instances so they appear on all pages within the course,
3236
// not just the course main page.
33-
$DB->set_field('block_instances', 'pagetypepattern', '*',
34-
['blockname' => 'course_search', 'pagetypepattern' => 'course-view-*']);
37+
$DB->set_field(
38+
'block_instances',
39+
'pagetypepattern',
40+
'*',
41+
['blockname' => 'course_search', 'pagetypepattern' => 'course-view-*']
42+
);
3543

3644
upgrade_block_savepoint(true, 2025070901, 'course_search');
3745
}
3846

3947
if ($oldversion < 2025070902) {
4048
// Enable showinsubcontexts so the block appears on activity pages
4149
// (child contexts of the course context).
42-
$DB->set_field('block_instances', 'showinsubcontexts', 1,
43-
['blockname' => 'course_search']);
50+
$DB->set_field(
51+
'block_instances',
52+
'showinsubcontexts',
53+
1,
54+
['blockname' => 'course_search']
55+
);
4456

4557
upgrade_block_savepoint(true, 2025070902, 'course_search');
4658
}

lang/en/block_course_search.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

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

27+
$string['chapter'] = 'Chapter';
28+
$string['course_search:addinstance'] = 'Add a new course search block';
29+
$string['course_search:myaddinstance'] = 'Add a new course search block to Dashboard';
30+
$string['noresults'] = 'No results found for "{$a}"';
2731
$string['pluginname'] = 'Course Search';
28-
$string['searchcourse'] = 'Search course content';
32+
$string['privacy:metadata'] = 'The Course Search block does not store any personal data.';
33+
$string['resultsfound'] = '{$a} results found';
2934
$string['search'] = 'Search';
30-
$string['searchresults'] = 'Search results for: {$a}';
31-
$string['noresults'] = 'No results found for "{$a}"';
35+
$string['searchcourse'] = 'Search course content';
3236
$string['searchinactivity'] = 'Search in {$a}';
33-
$string['resultsfound'] = '{$a} results found';
34-
$string['privacy:metadata'] = 'The Course Search block does not store any personal data.';
35-
$string['course_search:addinstance'] = 'Add a new course search block';
36-
$string['course_search:myaddinstance'] = 'Add a new course search block to Dashboard';
37-
$string['chapter'] = 'Chapter';
37+
$string['searchresults'] = 'Search results for: {$a}';

0 commit comments

Comments
 (0)