Skip to content

Commit

Permalink
Make codechecker happy again
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Oct 14, 2023
1 parent af2f159 commit 66e9945
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2023-10-14 - Make codechecker happy again
* 2023-10-10 - Updated Moodle Plugin CI to latest upstream recommendations
* 2023-04-30 - Tests: Updated Moodle Plugin CI to use PHP 8.1 and Postgres 13 from Moodle 4.1 on.

Expand Down
4 changes: 2 additions & 2 deletions classes/cohort_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ protected function definition() {

$mform->addElement('html', \html_writer::tag('div', get_string('cohortsintro', 'local_profilecohort').'<br />'.
get_string('invisiblecohortsnote', 'local_profilecohort'),
array('id' => 'intro', 'class' => 'box generalbox')));
['id' => 'intro', 'class' => 'box generalbox']));

if (!$cohorts) {
$cohorturl = new \moodle_url('/cohort/index.php');
$link = \html_writer::link($cohorturl, get_string('cohorts', 'core_cohort'));
$mform->addElement('html', \html_writer::tag('div', get_string('nocohorts', 'local_profilecohort', $link),
array('class' => 'alert alert-warning')));
['class' => 'alert alert-warning']));
} else {
foreach ($cohorts as $cohort) {
$mform->addElement('advcheckbox', "cohort[$cohort->id]", null, format_string($cohort->name));
Expand Down
4 changes: 2 additions & 2 deletions classes/field_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function delete($tablename) {
if (!$this->id) {
return;
}
$DB->delete_records($tablename, array('id' => $this->id));
$DB->delete_records($tablename, ['id' => $this->id]);
$this->id = null;
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public function add_form_field(MoodleQuickForm $mform, $values, $rulecount) {

$prefix = '';
if ($this->id) {
$actiongroup = array();
$actiongroup = [];
$actiongroup[] = $mform->createElement('static', '', '', '<br><div class="localprofile-rule-actions">');
if ($rulecount > 1) {
$moveopts = range(1, $rulecount);
Expand Down
4 changes: 2 additions & 2 deletions classes/field_text.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class field_text extends field_base {
self::MATCH_EXACT, self::MATCH_CONTAINS,
self::MATCH_NOTEXACT, self::MATCH_NOTCONTAINS,
self::MATCH_ISDEFINED, self::MATCH_NOTDEFINED,
self::MATCH_EMPTY, self::MATCH_NOTEMPTY
self::MATCH_EMPTY, self::MATCH_NOTEMPTY,
];

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function validation_internal($formdata, $id) {
$errors = [];
if (!in_array($formdata['matchtype'][$id], [
self::MATCH_ISDEFINED, self::MATCH_NOTDEFINED,
self::MATCH_EMPTY, self::MATCH_NOTEMPTY
self::MATCH_EMPTY, self::MATCH_NOTEMPTY,
])) {
if (empty($formdata['matchvalue'][$id])) {
$errors["matchvalue[$id]"] = get_string('required');
Expand Down
8 changes: 4 additions & 4 deletions classes/profilecohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function extra_tabs() {
new \tabobject('members', new \moodle_url($this->get_index_url(), ['action' => 'members']),
get_string('members', 'local_profilecohort')),
new \tabobject('cohorts', new \moodle_url('/local/profilecohort/cohorts.php'),
get_string('selectcohorts', 'local_profilecohort'))
get_string('selectcohorts', 'local_profilecohort')),
];
}

Expand All @@ -103,7 +103,7 @@ protected function output_members() {

$out .= \html_writer::tag('div', get_string('membersintro', 'local_profilecohort').'<br/>'.
get_string('invisiblecohortsnote', 'local_profilecohort'),
array('id' => 'intro', 'class' => 'box generalbox'));
['id' => 'intro', 'class' => 'box generalbox']);

$namefields = \core_user\fields::get_name_fields();
$namefields = preg_filter('/^/', 'u.', $namefields);
Expand Down Expand Up @@ -162,7 +162,7 @@ private function output_members_entry($cohortname, $cohortmembers, $lastcohortid
$out .= html_writer::start_div('card-header', ['id' => $id.'-heading']);
$out .= html_writer::start_tag('h2', ['class' => 'mb-0']);
$out .= html_writer::start_tag('button', ['class' => 'btn btn-link btn-block text-left pl-0', 'type' => 'button',
'data-toggle' => 'collapse', 'data-target' => '#'.$id, 'aria-expanded' => 'false', 'aria-controls' => $id]);
'data-toggle' => 'collapse', 'data-target' => '#'.$id, 'aria-expanded' => 'false', 'aria-controls' => $id, ]);
$out .= format_string($cohortname);
if ($cohortmembers) {
$out .= html_writer::tag('span', get_string('countusers', 'local_profilecohort', count($cohortmembers)),
Expand Down Expand Up @@ -190,7 +190,7 @@ private function output_members_entry($cohortname, $cohortmembers, $lastcohortid
}

$out .= html_writer::start_div('collapse', ['id' => $id, 'aria-labelledby' => $id.'-heading',
'data-parent' => '#profilecohort-cohortlist']);
'data-parent' => '#profilecohort-cohortlist', ]);
$out .= html_writer::div($content, 'card-body');
$out .= html_writer::end_div();

Expand Down
8 changes: 4 additions & 4 deletions classes/profilefields.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function process_form() {
if ($this->action == 'add') {
// Add a new, empty, rule to the end of the list, if requested.
if ($addid = optional_param('add', null, PARAM_INT)) {
$field = $DB->get_record('user_info_field', array('id' => $addid), 'id AS fieldid, name, datatype, param1',
$field = $DB->get_record('user_info_field', ['id' => $addid], 'id AS fieldid, name, datatype, param1',
MUST_EXIST);
if ($rule = field_base::make_instance($field)) {
$rules[] = $rule;
Expand All @@ -116,7 +116,7 @@ public function process_form() {
// Instantiate the form.
$custom = [
'rules' => $rules,
'values' => $this->get_possible_values()
'values' => $this->get_possible_values(),
];
$this->form = new fields_form(null, $custom);
$toform = ['action' => $this->action];
Expand Down Expand Up @@ -207,11 +207,11 @@ public function output_form() {
if ($this->action == 'view') {
$out .= \html_writer::tag('div', get_string('viewintro', 'local_profilecohort').'<br />'.
get_string('invisiblecohortsnote', 'local_profilecohort'),
array('id' => 'intro', 'class' => 'box generalbox'));
['id' => 'intro', 'class' => 'box generalbox']);
} else if ($this->action == 'add') {
$out .= \html_writer::tag('div', get_string('addintro', 'local_profilecohort').
'<br />'.get_string('invisiblecohortsnote', 'local_profilecohort'),
array('id' => 'intro', 'class' => 'box generalbox'));
['id' => 'intro', 'class' => 'box generalbox']);
}

if (!$this->get_possible_fields()) {
Expand Down
10 changes: 5 additions & 5 deletions db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
$observers = [
[
'eventname' => '\core\event\user_loggedin',
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile'
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile',
],
[
'eventname' => '\core\event\user_loggedinas',
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile_loginas'
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile_loginas',
],
[
'eventname' => '\core\event\user_created',
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile_created'
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile_created',
],
[
'eventname' => '\core\event\user_updated',
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile_updated'
]
'callback' => '\local_profilecohort\profilecohort::set_cohorts_from_profile_updated',
],
];
2 changes: 1 addition & 1 deletion db/tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
'day' => '*',
'dayofweek' => '*',
'month' => '*',
]
],
];
2 changes: 1 addition & 1 deletion tests/behat/behat_local_profilecohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function the_following_custom_user_profile_fields_exist(TableNode $table)
'datatype',
];
$optional = [
'param1' => ''
'param1' => '',
];

$data = $table->getHash();
Expand Down
30 changes: 15 additions & 15 deletions tests/rules_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ public function test_delete_rule() {
$ruledata = (object) [
'fieldid' => $this->fieldids['textfield'], 'datatype' => 'text',
'matchtype' => field_text::MATCH_EXACT,
'matchvalue' => 'testing', 'value' => $this->cohortids[0]
'matchvalue' => 'testing', 'value' => $this->cohortids[0],
];
$rule = field_base::make_instance($ruledata);
$rule->save(self::TABLENAME);
// Create a 'menu' rule.
$ruledata2 = (object) [
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[1]
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[1],
];
$rule = field_base::make_instance($ruledata2);
$rule->save(self::TABLENAME);
Expand Down Expand Up @@ -353,7 +353,7 @@ public function test_match_checkbox() {
// Create a 'checkbox' rule.
$ruledata = (object) [
'fieldid' => $this->fieldids['checkboxfield'], 'datatype' => 'checkbox',
'matchvalue' => 1, 'value' => $this->cohortids[0]
'matchvalue' => 1, 'value' => $this->cohortids[0],
];
$rule = field_base::make_instance($ruledata);
$rule->save(self::TABLENAME);
Expand Down Expand Up @@ -397,7 +397,7 @@ public function test_match_menu() {
// Create a 'menu' rule.
$ruledata = (object) [
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[0]
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[0],
];
$rule = field_base::make_instance($ruledata);
$rule->save(self::TABLENAME);
Expand Down Expand Up @@ -446,7 +446,7 @@ public function test_match_text() {
$ruledata = (object) [
'fieldid' => $this->fieldids['textfield'], 'datatype' => 'text',
'matchtype' => field_text::MATCH_EXACT,
'matchvalue' => 'Another test', 'value' => $this->cohortids[0]
'matchvalue' => 'Another test', 'value' => $this->cohortids[0],
];
$rule = field_base::make_instance($ruledata);
$rule->save(self::TABLENAME);
Expand Down Expand Up @@ -528,13 +528,13 @@ public function test_update_all_cohort_memberships() {
// the other matching 'Opt 2' to 'cohorts[1]'.
$ruledata1 = (object) [
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0]
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0],
];
$rule1 = field_base::make_instance($ruledata1);
$rule1->save(self::TABLENAME);
$ruledata2 = (object) [
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[1]
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[1],
];
$rule2 = field_base::make_instance($ruledata2);
$rule2->save(self::TABLENAME);
Expand Down Expand Up @@ -590,13 +590,13 @@ public function test_update_cohort_membership() {
// the other matching 'Opt 2' to 'cohorts[1]'.
$ruledata1 = (object)[
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0]
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0],
];
$rule1 = field_base::make_instance($ruledata1);
$rule1->save(self::TABLENAME);
$ruledata2 = (object)[
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[1]
'matchvalue' => 'Opt 2', 'value' => $this->cohortids[1],
];
$rule2 = field_base::make_instance($ruledata2);
$rule2->save(self::TABLENAME);
Expand Down Expand Up @@ -668,28 +668,28 @@ public function test_and_rules() {
// As 'menufield' == 'Opt 1' => cohort 0 AND next rule must match.
$ruledata1 = (object)[
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0], 'andnextrule' => 1
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0], 'andnextrule' => 1,
];
$rule1 = field_base::make_instance($ruledata1);
$rule1->save(self::TABLENAME);
// As 'checkboxfield' == 0 => cohort 1 AND next rule must match.
$ruledata2 = (object)[
'fieldid' => $this->fieldids['checkboxfield'], 'datatype' => 'checkbox',
'matchvalue' => '0', 'value' => $this->cohortids[1], 'andnextrule' => 1
'matchvalue' => '0', 'value' => $this->cohortids[1], 'andnextrule' => 1,
];
$rule2 = field_base::make_instance($ruledata2);
$rule2->save(self::TABLENAME);
// As 'textfield' == 'Fred' => cohort 2.
$ruledata3 = (object)[
'fieldid' => $this->fieldids['textfield'], 'datatype' => 'text',
'matchvalue' => 'Fred', 'value' => $this->cohortids[2], 'andnextrule' => 0
'matchvalue' => 'Fred', 'value' => $this->cohortids[2], 'andnextrule' => 0,
];
$rule3 = field_base::make_instance($ruledata3);
$rule3->save(self::TABLENAME);
// As 'textfield' == 'Fred' => cohort 3 - this rule should match on its own.
$ruledata4 = (object)[
'fieldid' => $this->fieldids['textfield'], 'datatype' => 'text',
'matchvalue' => 'Fred', 'value' => $this->cohortids[3], 'andnextrule' => 0
'matchvalue' => 'Fred', 'value' => $this->cohortids[3], 'andnextrule' => 0,
];
$rule4 = field_base::make_instance($ruledata4);
$rule4->save(self::TABLENAME);
Expand Down Expand Up @@ -759,14 +759,14 @@ public function test_and_rules_ending_in_and() {
// As 'menufield' == 'Opt 1' => cohort 0 AND next rule must match.
$ruledata1 = (object)[
'fieldid' => $this->fieldids['menufield'], 'datatype' => 'menu',
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0], 'andnextrule' => 1
'matchvalue' => 'Opt 1', 'value' => $this->cohortids[0], 'andnextrule' => 1,
];
$rule1 = field_base::make_instance($ruledata1);
$rule1->save(self::TABLENAME);
// As 'checkboxfield' == 0 => cohort 1 AND next rule must match.
$ruledata2 = (object)[
'fieldid' => $this->fieldids['checkboxfield'], 'datatype' => 'checkbox',
'matchvalue' => '0', 'value' => $this->cohortids[1], 'andnextrule' => 1
'matchvalue' => '0', 'value' => $this->cohortids[1], 'andnextrule' => 1,
];
$rule2 = field_base::make_instance($ruledata2);
$rule2->save(self::TABLENAME);
Expand Down

0 comments on commit 66e9945

Please sign in to comment.