Skip to content

Commit

Permalink
Address PHP 8.2 notices, and codechecker warnings. Fixes #161
Browse files Browse the repository at this point in the history
  • Loading branch information
FMCorz committed Oct 27, 2023
1 parent 1bb5785 commit 6f61f31
Show file tree
Hide file tree
Showing 89 changed files with 538 additions and 495 deletions.
2 changes: 1 addition & 1 deletion backup/moodle2/backup_xp_block_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function define_my_steps() {
* @return array
*/
public function get_fileareas() {
return array();
return [];
}

/**
Expand Down
20 changes: 10 additions & 10 deletions backup/moodle2/backup_xp_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ protected function define_structure() {
$userinfo = $this->get_setting_value('users');

// Define each element separated.
$xpconfig = new backup_nested_element('config', array('courseid'), array(
$xpconfig = new backup_nested_element('config', ['courseid'], [
'enabled', 'levels', 'lastlogpurge', 'enableladder', 'enableinfos', 'levelsdata',
'enablelevelupnotif', 'enablecustomlevelbadges', 'maxactionspertime', 'timeformaxactions', 'timebetweensameactions',
'identitymode', 'rankmode', 'neighbours', 'enablecheatguard', 'defaultfilters', 'laddercols', 'instructions',
'instructions_format', 'blocktitle', 'blockdescription', 'blockrecentactivity', 'blockrankingsnapshot'
));
'instructions_format', 'blocktitle', 'blockdescription', 'blockrecentactivity', 'blockrankingsnapshot',
]);
$xpfilters = new backup_nested_element('filters');
$xpfilter = new backup_nested_element('filter', array('courseid'), array('ruledata', 'points', 'sortorder', 'category'));
$xpfilter = new backup_nested_element('filter', ['courseid'], ['ruledata', 'points', 'sortorder', 'category']);
$xplevels = new backup_nested_element('xps');
$xplevel = new backup_nested_element('xp', array('courseid'), array('userid', 'xp'));
$xplevel = new backup_nested_element('xp', ['courseid'], ['userid', 'xp']);
$xplogs = new backup_nested_element('logs');
$xplog = new backup_nested_element('log', array('courseid'), array('userid', 'eventname', 'xp', 'time'));
$xplog = new backup_nested_element('log', ['courseid'], ['userid', 'eventname', 'xp', 'time']);

// Prepare the structure.
$xp = $this->prepare_block_structure($xpconfig);
Expand All @@ -68,10 +68,10 @@ protected function define_structure() {
}

// Define sources.
$xpconfig->set_source_table('block_xp_config', array('courseid' => backup::VAR_COURSEID));
$xpfilter->set_source_table('block_xp_filters', array('courseid' => backup::VAR_COURSEID));
$xplevel->set_source_table('block_xp', array('courseid' => backup::VAR_COURSEID));
$xplog->set_source_table('block_xp_log', array('courseid' => backup::VAR_COURSEID));
$xpconfig->set_source_table('block_xp_config', ['courseid' => backup::VAR_COURSEID]);
$xpfilter->set_source_table('block_xp_filters', ['courseid' => backup::VAR_COURSEID]);
$xplevel->set_source_table('block_xp', ['courseid' => backup::VAR_COURSEID]);
$xplog->set_source_table('block_xp_log', ['courseid' => backup::VAR_COURSEID]);

// Annotations.
$xplevel->annotate_ids('user', 'userid');
Expand Down
6 changes: 3 additions & 3 deletions backup/moodle2/restore_xp_block_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function define_my_steps() {
* @return array
*/
public function get_fileareas() {
return array();
return [];
}

/**
Expand All @@ -75,15 +75,15 @@ public function get_configdata_encoded_attributes() {
* @return array
*/
public static function define_decode_contents() {
return array();
return [];
}

/**
* Define decode rules.
* @return array
*/
public static function define_decode_rules() {
return array();
return [];
}

/**
Expand Down
10 changes: 5 additions & 5 deletions backup/moodle2/restore_xp_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function execute_condition() {
protected function define_structure() {
global $DB;

$paths = array();
$paths = [];
$userinfo = $this->get_setting_value('users');

// Define each path.
Expand Down Expand Up @@ -95,10 +95,10 @@ protected function process_block($data) {
// Removing old preferences.
$sql = $DB->sql_like('name', ':name');
$DB->delete_records_select('user_preferences', $sql, [
'name' => 'block_xp-notice-block_intro_' . $courseid
'name' => 'block_xp-notice-block_intro_' . $courseid,
]);
$DB->delete_records_select('user_preferences', $sql, [
'name' => 'block_xp_notify_level_up_' . $courseid
'name' => 'block_xp_notify_level_up_' . $courseid,
]);
}
}
Expand All @@ -115,7 +115,7 @@ protected function process_config($data) {
$data['defaultfilters'] = \block_xp\local\config\course_world_config::DEFAULT_FILTERS_STATIC;
}

if ($DB->record_exists('block_xp_config', array('courseid' => $data['courseid']))) {
if ($DB->record_exists('block_xp_config', ['courseid' => $data['courseid']])) {
$this->log('block_xp: config not restored, existing config was found', backup::LOG_DEBUG);
return;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ protected function process_xp($data) {
$data['courseid'] = $this->get_courseid();
$data['userid'] = $this->get_mappingid('user', $data['userid']);
$data['lvl'] = 1; // This is no longer used, and is hardcoded to 1.
if ($DB->record_exists('block_xp', array('courseid' => $data['courseid'], 'userid' => $data['userid']))) {
if ($DB->record_exists('block_xp', ['courseid' => $data['courseid'], 'userid' => $data['userid']])) {
$this->log("block_xp: XP of user with id '{$data['userid']}' not restored, existing entry found", backup::LOG_DEBUG);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion classes/external/search_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function execute($query) {

array_unshift($courses, array_merge((array) $SITE, [
'displayname' => external_utils::format_string(get_course_display_name_for_list($SITE),
context_course::instance($SITE->id))
context_course::instance($SITE->id)),
]));
}

Expand Down
6 changes: 3 additions & 3 deletions classes/external/search_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public static function execute($courseid, $query) {
$modules[] = [
'cmid' => $cm->id,
'contextid' => $cm->context->id,
'name' => $cm->get_formatted_name()
'name' => $cm->get_formatted_name(),
];
}
}

if (!empty($modules)) {
$sections[] = [
'name' => $courseformat->get_section_name($sectionnum),
'modules' => $modules
'modules' => $modules,
];
}
}
Expand All @@ -114,7 +114,7 @@ public static function execute_returns() {
'cmid' => new external_value(PARAM_INT),
'contextid' => new external_value(PARAM_INT),
'name' => new external_value(PARAM_RAW),
]))
])),
]));
}

Expand Down
6 changes: 3 additions & 3 deletions classes/external/set_default_levels_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function execute_parameters() {
'base' => new external_value(PARAM_INT),
'incr' => new external_value(PARAM_INT),
'coef' => new external_value(PARAM_FLOAT),
])
]),
]);
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public static function execute($levels, $algo) {
$writer = di::get('levels_info_writer');
$writer->save_defaults([
'levels' => $params['levels'],
'algo' => $params['algo']
'algo' => $params['algo'],
]);

return (object) ['success' => true];
Expand All @@ -107,7 +107,7 @@ public static function execute($levels, $algo) {
*/
public static function execute_returns() {
return new external_single_structure([
'success' => new external_value(PARAM_BOOL)
'success' => new external_value(PARAM_BOOL),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions classes/external/set_levels_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function execute_parameters() {
'base' => new external_value(PARAM_INT),
'incr' => new external_value(PARAM_INT),
'coef' => new external_value(PARAM_FLOAT),
])
]),
]);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ public static function execute($courseid, $levels, $algo) {
$writer = di::get('levels_info_writer');
$writer->save_for_world($world, [
'levels' => $params['levels'],
'algo' => $params['algo']
'algo' => $params['algo'],
]);

return (object) ['success' => true];
Expand All @@ -115,7 +115,7 @@ public static function execute($courseid, $levels, $algo) {
*/
public static function execute_returns() {
return new external_single_structure([
'success' => new external_value(PARAM_BOOL)
'success' => new external_value(PARAM_BOOL),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion classes/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function delete() {
if (!$this->id) {
throw new coding_exception('ID of the filter is unknown.');
}
$DB->delete_records('block_xp_filters', array('id' => $this->id));
$DB->delete_records('block_xp_filters', ['id' => $this->id]);
}

/**
Expand Down
16 changes: 8 additions & 8 deletions classes/form/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ public function definition() {
$mform->addElement('selectyesno', 'enableladder', get_string('enableladder', 'block_xp'));
$mform->addHelpButton('enableladder', 'enableladder', 'block_xp');

$mform->addElement('select', 'identitymode', get_string('anonymity', 'block_xp'), array(
$mform->addElement('select', 'identitymode', get_string('anonymity', 'block_xp'), [
course_world_config::IDENTITY_OFF => get_string('hideparticipantsidentity', 'block_xp'),
course_world_config::IDENTITY_ON => get_string('displayparticipantsidentity', 'block_xp'),
));
]);
$mform->addHelpButton('identitymode', 'anonymity', 'block_xp');
$mform->disabledIf('identitymode', 'enableladder', 'eq', 0);

$mform->addElement('select', 'neighbours', get_string('limitparticipants', 'block_xp'), array(
$mform->addElement('select', 'neighbours', get_string('limitparticipants', 'block_xp'), [
0 => get_string('displayeveryone', 'block_xp'),
1 => get_string('displayoneneigbour', 'block_xp'),
2 => get_string('displaynneighbours', 'block_xp', '2'),
3 => get_string('displaynneighbours', 'block_xp', '3'),
4 => get_string('displaynneighbours', 'block_xp', '4'),
5 => get_string('displaynneighbours', 'block_xp', '5'),
));
]);
$mform->addHelpButton('neighbours', 'limitparticipants', 'block_xp');
$mform->disabledIf('neighbours', 'enableladder', 'eq', 0);

$mform->addElement('select', 'rankmode', get_string('ranking', 'block_xp'), array(
$mform->addElement('select', 'rankmode', get_string('ranking', 'block_xp'), [
course_world_config::RANK_OFF => get_string('hiderank', 'block_xp'),
course_world_config::RANK_ON => get_string('displayrank', 'block_xp'),
course_world_config::RANK_REL => get_string('displayrelativerank', 'block_xp'),
));
]);
$mform->addHelpButton('rankmode', 'ranking', 'block_xp');
$mform->disabledIf('rankmode', 'enableladder', 'eq', 0);

Expand All @@ -116,7 +116,7 @@ public function definition() {

$mform->addElement('block_xp_form_itemspertime', 'maxactionspertime', get_string('maxactionspertime', 'block_xp'), [
'maxunit' => 60,
'itemlabel' => get_string('actions', 'block_xp')
'itemlabel' => get_string('actions', 'block_xp'),
]);
$mform->addHelpButton('maxactionspertime', 'maxactionspertime', 'block_xp');
$mform->disabledIf('maxactionspertime', 'enablecheatguard', 'eq', 0);
Expand Down Expand Up @@ -255,7 +255,7 @@ public function set_data($data) {
if (isset($data['maxactionspertime']) && isset($data['timeformaxactions'])) {
$data['maxactionspertime'] = [
'points' => (int) $data['maxactionspertime'],
'time' => (int) $data['timeformaxactions']
'time' => (int) $data['timeformaxactions'],
];
unset($data['timeformaxactions']);
}
Expand Down
12 changes: 6 additions & 6 deletions classes/form/itemspertime.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function _createElements() { // @codingStandardsIgnoreLine

$item = $this->my_create_element('text', 'points', $this->_options['itemlabel'], [
'size' => 4,
'placeholder' => !empty($this->_options['itemlabel']) ? $this->_options['itemlabel'] : null
'placeholder' => !empty($this->_options['itemlabel']) ? $this->_options['itemlabel'] : null,
]);
if (method_exists($item, 'set_force_ltr')) {
$item->set_force_ltr(true);
Expand All @@ -150,7 +150,7 @@ function _createElements() { // @codingStandardsIgnoreLine
$this->_elements[] = $in;

$time = $this->my_create_element('text', 'time', get_string('time', 'form'), [
'size' => 3
'size' => 3,
]);
if (method_exists($time, 'set_force_ltr')) {
$time->set_force_ltr(true);
Expand Down Expand Up @@ -215,14 +215,14 @@ function onQuickFormEvent($event, $arg, &$caller) { // @codingStandardsIgnoreLin
} else {
$finalval = [
'points' => isset($value['points']) ? max(0, $value['points']) : 0,
'enabled' => !isset($value['enabled']) || !empty($value['enabled'])
'enabled' => !isset($value['enabled']) || !empty($value['enabled']),
];
if (!empty($value['time'])) {
if (!is_array($value['time'])) {
list($time, $timeunit) = $this->seconds_to_unit($value['time']);
$finalval += [
'time' => $time,
'timeunit' => $timeunit
'timeunit' => $timeunit,
];
} else {
$finalval += $value['time'];
Expand Down Expand Up @@ -289,8 +289,8 @@ function exportValue(&$submitvalues, $notused = false) { // @codingStandardsIgno

return [$this->getName() => [
'time' => max(0, $values['time'] * $values['timeunit']),
'points' => max(0, (int) $values['points'])
]];
'points' => max(0, (int) $values['points']),
], ];
}
}

Expand Down
6 changes: 3 additions & 3 deletions classes/form/levels_with_algo.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ public function get_levels_from_data() {
'base' => $data->basexp,
'coef' => $data->coefxp,
'xp' => [
'1' => 0
'1' => 0,
],
'desc' => [],
'name' => []
'name' => [],
];

$keys = ['xp', 'desc', 'name'];
Expand Down Expand Up @@ -209,7 +209,7 @@ public function set_data_from_levels(\block_xp\local\xp\algo_levels_info $levels
* @return array of errors.
*/
public function validation($data, $files) {
$errors = array();
$errors = [];
if ($data['levels'] < 2) {
$errors['levels'] = get_string('errorlevelsincorrect', 'block_xp');
}
Expand Down
2 changes: 1 addition & 1 deletion classes/form/user_xp.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function definition() {
* @return array of errors.
*/
public function validation($data, $files) {
$errors = array();
$errors = [];

// Validating the XP points.
$xp = (int) $data['xp'];
Expand Down
2 changes: 1 addition & 1 deletion classes/form/visuals.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function definition() {

if ($this->_customdata['showpromo'] ?? true) {
$addonrequired = $renderer->render_from_template('block_xp/addon-required', [
'promourl' => $this->_customdata['promourl']
'promourl' => $this->_customdata['promourl'],
]);
$mform->addElement('select', 'currencytheme', get_string('currencysign', 'block_xp') . ' ' . $addonrequired,
['' => get_string('currencysignxp', 'block_xp')], ['disabled' => 'disabled']);
Expand Down
4 changes: 2 additions & 2 deletions classes/local/block/course_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class course_block extends block_base {
public function applicable_formats() {
$mode = \block_xp\di::get('config')->get('context');
if ($mode == CONTEXT_SYSTEM) {
return array('site' => true, 'course' => true, 'my' => true);
return ['site' => true, 'course' => true, 'my' => true];
}
return array('course' => true);
return ['course' => true];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/local/block/course_world_instance_finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function get_candidates_in_context($name, context $context) {
'fpcontextid3' => $fpcontext->id,
'syscontextid' => $context->id,
'syspagetype' => 'my-index',
'syssubpage' => $page->id
'syssubpage' => $page->id,
];

// Return instances.
Expand Down
2 changes: 1 addition & 1 deletion classes/local/block/default_instance_finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get_instance_in_context($name, context $context) {

$params = [
'name' => preg_replace('/^block_/i', '', $name),
'contextid' => $context->id
'contextid' => $context->id,
];

$records = $this->db->get_records_sql($sql, $params);
Expand Down
2 changes: 1 addition & 1 deletion classes/local/config/course_world_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(config $adminconfig, moodle_database $db, $courseid)
// Note that we set the admin config as immutable, just to make sure we don't change it.
$defaults = new config_stack([
new immutable_config($adminconfig),
new default_course_world_config()
new default_course_world_config(),
]);

$config = new \block_xp\local\config\table_row_config($db, 'block_xp_config',
Expand Down
Loading

0 comments on commit 6f61f31

Please sign in to comment.