From 6f61f3196b17a2f01166900f1d48f211dd7cf18d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Massart?= Date: Fri, 27 Oct 2023 15:32:02 +0800 Subject: [PATCH] Address PHP 8.2 notices, and codechecker warnings. Fixes #161 --- backup/moodle2/backup_xp_block_task.class.php | 2 +- backup/moodle2/backup_xp_stepslib.php | 20 ++--- .../moodle2/restore_xp_block_task.class.php | 6 +- backup/moodle2/restore_xp_stepslib.php | 10 +-- classes/external/search_courses.php | 2 +- classes/external/search_modules.php | 6 +- classes/external/set_default_levels_info.php | 6 +- classes/external/set_levels_info.php | 6 +- classes/filter.php | 2 +- classes/form/config.php | 16 ++-- classes/form/itemspertime.php | 12 +-- classes/form/levels_with_algo.php | 6 +- classes/form/user_xp.php | 2 +- classes/form/visuals.php | 2 +- classes/local/block/course_block.php | 4 +- .../block/course_world_instance_finder.php | 2 +- .../local/block/default_instance_finder.php | 2 +- classes/local/config/course_world_config.php | 2 +- .../controller/admin_levels_controller.php | 6 +- .../controller/admin_route_controller.php | 2 +- .../controller/admin_rules_controller.php | 12 +-- .../controller/admin_visuals_controller.php | 4 +- classes/local/controller/infos_controller.php | 6 +- .../local/controller/ladder_controller.php | 2 +- .../local/controller/levels_controller.php | 8 +- classes/local/controller/log_controller.php | 2 +- classes/local/controller/promo_controller.php | 8 +- .../local/controller/report_controller.php | 4 +- classes/local/controller/rules_controller.php | 8 +- .../local/controller/visuals_controller.php | 8 +- classes/local/default_container.php | 2 +- ...adge_url_resolver_course_world_factory.php | 2 +- .../course_world_leaderboard_factory.php | 2 +- ..._world_leaderboard_factory_with_config.php | 2 +- .../course_world_navigation_factory.php | 2 +- ...efault_course_world_navigation_factory.php | 24 +++--- .../leaderboard/course_user_leaderboard.php | 13 ++- .../course_user_event_collection_logger.php | 8 +- .../local/logger/global_collection_logger.php | 2 +- .../course_level_up_notification_service.php | 3 + .../observer/default_observer_rules_maker.php | 6 +- .../observer/default_state_store_observer.php | 4 +- classes/local/observer/observer.php | 6 +- classes/local/reason/event_name_reason.php | 3 + classes/local/routing/ajax_routes_config.php | 2 +- .../local/routing/default_routes_config.php | 24 +++--- classes/local/routing/route_definition.php | 11 +++ classes/local/rule/event_lister.php | 12 +-- classes/local/serializer/level_serializer.php | 2 +- .../serializer/levels_info_serializer.php | 4 +- .../setting/compatibility_check_setting.php | 10 +-- .../local/setting/default_settings_maker.php | 8 +- .../setting/recommended_plugins_setting.php | 4 +- .../default_shortcodes_definition_maker.php | 12 +-- classes/local/shortcode/handler.php | 2 +- classes/local/sql/limit.php | 5 ++ .../strategy/global_collection_strategy.php | 2 +- .../task/default_tasks_definition_maker.php | 6 +- classes/local/xp/admin_filter_manager.php | 16 ++-- classes/local/xp/course_filter_manager.php | 4 +- classes/local/xp/course_user_state_store.php | 8 +- classes/local/xp/levels_info_writer.php | 4 +- classes/local/xp/state_rank.php | 5 ++ classes/output/leaderboard_table.php | 7 +- classes/output/log_table.php | 18 ++-- classes/output/report_table.php | 10 +-- classes/privacy/provider.php | 6 +- classes/rule.php | 6 +- classes/rule_base.php | 6 +- classes/rule_cm.php | 10 +-- classes/rule_event.php | 4 +- classes/rule_property.php | 14 ++-- classes/ruleset.php | 14 ++-- db/access.php | 78 +++++++++--------- db/caches.php | 16 ++-- db/services.php | 6 +- db/upgrade.php | 8 +- lib.php | 4 +- renderer.php | 82 +++++++++---------- tests/algo_levels_info_test.php | 32 ++++---- tests/backup_test.php | 34 ++++---- .../course_world_collection_strategy_test.php | 2 +- tests/course_world_test.php | 76 ++++++++--------- tests/filters_test.php | 68 +++++++-------- tests/fixtures/events.php | 2 +- tests/leaderboard_factory_test.php | 18 ++-- tests/levels_info_writer_test.php | 14 ++-- tests/privacy_provider_test.php | 64 +++++++-------- tests/rules_test.php | 36 ++++---- 89 files changed, 538 insertions(+), 495 deletions(-) diff --git a/backup/moodle2/backup_xp_block_task.class.php b/backup/moodle2/backup_xp_block_task.class.php index 62be0197..1e960d21 100644 --- a/backup/moodle2/backup_xp_block_task.class.php +++ b/backup/moodle2/backup_xp_block_task.class.php @@ -53,7 +53,7 @@ protected function define_my_steps() { * @return array */ public function get_fileareas() { - return array(); + return []; } /** diff --git a/backup/moodle2/backup_xp_stepslib.php b/backup/moodle2/backup_xp_stepslib.php index d5742f0c..0d17a7b0 100644 --- a/backup/moodle2/backup_xp_stepslib.php +++ b/backup/moodle2/backup_xp_stepslib.php @@ -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); @@ -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'); diff --git a/backup/moodle2/restore_xp_block_task.class.php b/backup/moodle2/restore_xp_block_task.class.php index 1c853dc6..724b9ae0 100644 --- a/backup/moodle2/restore_xp_block_task.class.php +++ b/backup/moodle2/restore_xp_block_task.class.php @@ -61,7 +61,7 @@ protected function define_my_steps() { * @return array */ public function get_fileareas() { - return array(); + return []; } /** @@ -75,7 +75,7 @@ public function get_configdata_encoded_attributes() { * @return array */ public static function define_decode_contents() { - return array(); + return []; } /** @@ -83,7 +83,7 @@ public static function define_decode_contents() { * @return array */ public static function define_decode_rules() { - return array(); + return []; } /** diff --git a/backup/moodle2/restore_xp_stepslib.php b/backup/moodle2/restore_xp_stepslib.php index 11ed2605..797da6e5 100644 --- a/backup/moodle2/restore_xp_stepslib.php +++ b/backup/moodle2/restore_xp_stepslib.php @@ -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. @@ -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, ]); } } @@ -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; } @@ -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; } diff --git a/classes/external/search_courses.php b/classes/external/search_courses.php index 2ac8a771..33063a85 100644 --- a/classes/external/search_courses.php +++ b/classes/external/search_courses.php @@ -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)), ])); } diff --git a/classes/external/search_modules.php b/classes/external/search_modules.php index 2f13fbb9..9f8e478d 100644 --- a/classes/external/search_modules.php +++ b/classes/external/search_modules.php @@ -86,7 +86,7 @@ public static function execute($courseid, $query) { $modules[] = [ 'cmid' => $cm->id, 'contextid' => $cm->context->id, - 'name' => $cm->get_formatted_name() + 'name' => $cm->get_formatted_name(), ]; } } @@ -94,7 +94,7 @@ public static function execute($courseid, $query) { if (!empty($modules)) { $sections[] = [ 'name' => $courseformat->get_section_name($sectionnum), - 'modules' => $modules + 'modules' => $modules, ]; } } @@ -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), - ])) + ])), ])); } diff --git a/classes/external/set_default_levels_info.php b/classes/external/set_default_levels_info.php index 616936fe..44549217 100644 --- a/classes/external/set_default_levels_info.php +++ b/classes/external/set_default_levels_info.php @@ -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), - ]) + ]), ]); } @@ -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]; @@ -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), ]); } diff --git a/classes/external/set_levels_info.php b/classes/external/set_levels_info.php index 198f092b..3f38a8c2 100644 --- a/classes/external/set_levels_info.php +++ b/classes/external/set_levels_info.php @@ -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), - ]) + ]), ]); } @@ -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]; @@ -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), ]); } diff --git a/classes/filter.php b/classes/filter.php index fa0aba6e..3be965dc 100644 --- a/classes/filter.php +++ b/classes/filter.php @@ -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]); } /** diff --git a/classes/form/config.php b/classes/form/config.php index 0881ac60..cd6c2ce7 100644 --- a/classes/form/config.php +++ b/classes/form/config.php @@ -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); @@ -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); @@ -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']); } diff --git a/classes/form/itemspertime.php b/classes/form/itemspertime.php index ebea2ca8..660b639b 100644 --- a/classes/form/itemspertime.php +++ b/classes/form/itemspertime.php @@ -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); @@ -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); @@ -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']; @@ -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']), + ], ]; } } diff --git a/classes/form/levels_with_algo.php b/classes/form/levels_with_algo.php index f6a9b9bf..ebf62666 100644 --- a/classes/form/levels_with_algo.php +++ b/classes/form/levels_with_algo.php @@ -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']; @@ -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'); } diff --git a/classes/form/user_xp.php b/classes/form/user_xp.php index 459495ad..40145421 100644 --- a/classes/form/user_xp.php +++ b/classes/form/user_xp.php @@ -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']; diff --git a/classes/form/visuals.php b/classes/form/visuals.php index 35a4451e..ee0d4ecd 100644 --- a/classes/form/visuals.php +++ b/classes/form/visuals.php @@ -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']); diff --git a/classes/local/block/course_block.php b/classes/local/block/course_block.php index 14c1e15c..e9421695 100644 --- a/classes/local/block/course_block.php +++ b/classes/local/block/course_block.php @@ -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]; } /** diff --git a/classes/local/block/course_world_instance_finder.php b/classes/local/block/course_world_instance_finder.php index 906da484..b4748d1f 100644 --- a/classes/local/block/course_world_instance_finder.php +++ b/classes/local/block/course_world_instance_finder.php @@ -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. diff --git a/classes/local/block/default_instance_finder.php b/classes/local/block/default_instance_finder.php index 3917f636..6f3f68a4 100644 --- a/classes/local/block/default_instance_finder.php +++ b/classes/local/block/default_instance_finder.php @@ -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); diff --git a/classes/local/config/course_world_config.php b/classes/local/config/course_world_config.php index cd556dc4..6d9d96cd 100644 --- a/classes/local/config/course_world_config.php +++ b/classes/local/config/course_world_config.php @@ -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', diff --git a/classes/local/controller/admin_levels_controller.php b/classes/local/controller/admin_levels_controller.php index f6dcea71..684d4cb8 100644 --- a/classes/local/controller/admin_levels_controller.php +++ b/classes/local/controller/admin_levels_controller.php @@ -81,9 +81,9 @@ protected function get_react_module() { 'defaultBadgeUrls' => $defaultbadges, 'addon' => [ 'activated' => di::get('addon')->is_activated(), - 'promourl' => $this->urlresolver->reverse('admin/promo')->out(false) - ] - ] + 'promourl' => $this->urlresolver->reverse('admin/promo')->out(false), + ], + ], ]; } } diff --git a/classes/local/controller/admin_route_controller.php b/classes/local/controller/admin_route_controller.php index 5cd27f34..b45df943 100644 --- a/classes/local/controller/admin_route_controller.php +++ b/classes/local/controller/admin_route_controller.php @@ -92,7 +92,7 @@ protected function page_warning_editing_defaults($routename = '') { $url = $this->urlresolver->reverse($routename, ['courseid' => SITEID]); echo di::get('renderer')->notification_without_close(strip_tags( markdown_to_html(get_string('editingdefaultsettingsinwholesitemodenotice', 'block_xp', [ - 'url' => $url->out(false) + 'url' => $url->out(false), ])), '' ), \core\output\notification::NOTIFY_WARNING); diff --git a/classes/local/controller/admin_rules_controller.php b/classes/local/controller/admin_rules_controller.php index 106746a0..4950d83e 100644 --- a/classes/local/controller/admin_rules_controller.php +++ b/classes/local/controller/admin_rules_controller.php @@ -50,7 +50,7 @@ protected function define_optional_params() { return [ ['revert', false, PARAM_BOOL, false], ['reset', false, PARAM_BOOL, false], - ['confirm', false, PARAM_BOOL, false] + ['confirm', false, PARAM_BOOL, false], ]; } @@ -104,7 +104,7 @@ protected function handle_save() { * @return void */ protected function save_filters($filters, $existingfilters, $category = null) { - $filterids = array(); + $filterids = []; foreach ($filters as $filterdata) { $data = $filterdata; $data['ruledata'] = json_encode($data['rule'], true); @@ -151,17 +151,17 @@ protected function get_available_rules() { (object) [ 'name' => get_string('ruleevent', 'block_xp'), 'info' => get_string('ruleeventinfo', 'block_xp'), - 'rule' => new \block_xp_rule_event() + 'rule' => new \block_xp_rule_event(), ], (object) [ 'name' => get_string('ruleproperty', 'block_xp'), 'info' => get_string('rulepropertyinfo', 'block_xp'), - 'rule' => new \block_xp_rule_property() + 'rule' => new \block_xp_rule_property(), ], (object) [ 'name' => get_string('ruleset', 'block_xp'), 'info' => get_string('rulesetinfo', 'block_xp'), - 'rule' => new \block_xp_ruleset() + 'rule' => new \block_xp_ruleset(), ], ]; return $rules; @@ -170,7 +170,7 @@ protected function get_available_rules() { /** * Get default filters. * - * @return block_xp_filter + * @return \block_xp_filter */ protected function get_default_filter() { return \block_xp_filter::load_from_data(['rule' => new \block_xp_ruleset()]); diff --git a/classes/local/controller/admin_visuals_controller.php b/classes/local/controller/admin_visuals_controller.php index 9181210b..935349e6 100644 --- a/classes/local/controller/admin_visuals_controller.php +++ b/classes/local/controller/admin_visuals_controller.php @@ -54,7 +54,7 @@ class admin_visuals_controller extends admin_route_controller { protected function define_form() { return new \block_xp\form\visuals($this->pageurl->out(false), [ 'fmoptions' => $this->get_filemanager_options(), - 'promourl' => $this->urlresolver->reverse('admin/promo') + 'promourl' => $this->urlresolver->reverse('admin/promo'), ]); } @@ -102,7 +102,7 @@ protected function get_initial_form_data() { 0, $this->get_filemanager_options()); return [ - 'badges' => $draftitemid + 'badges' => $draftitemid, ]; } diff --git a/classes/local/controller/infos_controller.php b/classes/local/controller/infos_controller.php index f5bf9319..8d1775f5 100644 --- a/classes/local/controller/infos_controller.php +++ b/classes/local/controller/infos_controller.php @@ -57,7 +57,7 @@ protected function permissions_checks() { protected function define_optional_params() { return [ - ['edit', false, PARAM_BOOL, true] + ['edit', false, PARAM_BOOL, true], ]; } @@ -106,8 +106,8 @@ protected function page_content() { $form = $this->get_form(); $form->set_data((object) ['instructions' => [ 'text' => $instructions, - 'format' => $instructionsformat - ]]); + 'format' => $instructionsformat, + ], ]); $form->display(); } else if ($hasinstructions) { diff --git a/classes/local/controller/ladder_controller.php b/classes/local/controller/ladder_controller.php index 30f673eb..7ea66f4e 100644 --- a/classes/local/controller/ladder_controller.php +++ b/classes/local/controller/ladder_controller.php @@ -63,7 +63,7 @@ protected function page_setup() { */ protected function define_optional_params() { return [ - ['pagesize', 0, PARAM_INT, false] + ['pagesize', 0, PARAM_INT, false], ]; } diff --git a/classes/local/controller/levels_controller.php b/classes/local/controller/levels_controller.php index 984a77ec..d83eb836 100644 --- a/classes/local/controller/levels_controller.php +++ b/classes/local/controller/levels_controller.php @@ -47,7 +47,7 @@ class levels_controller extends page_controller { protected function define_optional_params() { return [ ['reset', false, PARAM_BOOL, false], - ['confirm', false, PARAM_BOOL, false] + ['confirm', false, PARAM_BOOL, false], ]; } @@ -99,9 +99,9 @@ protected function get_react_module() { 'addon' => [ 'activated' => di::get('addon')->is_activated(), 'enablepromo' => (bool) di::get('config')->get('enablepromoincourses'), - 'promourl' => $this->urlresolver->reverse('promo', ['courseid' => $world->get_courseid()])->out(false) - ] - ] + 'promourl' => $this->urlresolver->reverse('promo', ['courseid' => $world->get_courseid()])->out(false), + ], + ], ]; } diff --git a/classes/local/controller/log_controller.php b/classes/local/controller/log_controller.php index 21f1ceea..4b923362 100644 --- a/classes/local/controller/log_controller.php +++ b/classes/local/controller/log_controller.php @@ -61,7 +61,7 @@ protected function permissions_checks() { protected function define_optional_params() { return [ - ['userid', null, PARAM_INT] + ['userid', null, PARAM_INT], ]; } diff --git a/classes/local/controller/promo_controller.php b/classes/local/controller/promo_controller.php index 5de2b2c9..4365de5d 100644 --- a/classes/local/controller/promo_controller.php +++ b/classes/local/controller/promo_controller.php @@ -62,7 +62,7 @@ class promo_controller extends route_controller { protected function define_optional_params() { return [ - ['sent', 0, PARAM_INT, false] + ['sent', 0, PARAM_INT, false], ]; } @@ -174,8 +174,8 @@ protected function content_not_installed() { 'intro' => get_string('promointro', 'block_xp'), 'actions' => [ new single_button(new moodle_url($siteurl), $getxpstr, 'get', - defined('single_button::BUTTON_PRIMARY') ? single_button::BUTTON_PRIMARY : true) - ] + defined('single_button::BUTTON_PRIMARY') ? single_button::BUTTON_PRIMARY : true), + ], ]); $new = '🆕'; @@ -308,7 +308,7 @@ protected function content_installed() { if ($addon->is_out_of_sync()) { echo $output->notification_without_close(markdown_to_html(get_string('pluginsoutofsync', 'block_xp', [ - 'url' => $outofsyncurl->out(false) + 'url' => $outofsyncurl->out(false), ])), 'error'); } diff --git a/classes/local/controller/report_controller.php b/classes/local/controller/report_controller.php index 4dd1ca3d..8ec33a03 100644 --- a/classes/local/controller/report_controller.php +++ b/classes/local/controller/report_controller.php @@ -171,7 +171,7 @@ protected function get_bottom_action_buttons() { new url($this->pageurl->get_compatible_url(), [ 'resetdata' => 1, 'sesskey' => sesskey(), - 'group' => $groupid + 'group' => $groupid, ]), $strreset, 'get' @@ -191,7 +191,7 @@ protected function page_content() { echo $this->get_renderer()->confirm( empty($groupid) ? get_string('reallyresetdata', 'block_xp') : get_string('reallyresetgroupdata', 'block_xp'), new url($this->pageurl->get_compatible_url(), ['resetdata' => 1, 'confirm' => 1, - 'sesskey' => sesskey(), 'group' => $groupid]), + 'sesskey' => sesskey(), 'group' => $groupid, ]), new url($this->pageurl->get_compatible_url()) ); return; diff --git a/classes/local/controller/rules_controller.php b/classes/local/controller/rules_controller.php index 97482c68..2e299c34 100644 --- a/classes/local/controller/rules_controller.php +++ b/classes/local/controller/rules_controller.php @@ -56,7 +56,7 @@ class rules_controller extends page_controller { protected function define_optional_params() { return [ ['reset', false, PARAM_BOOL, false], - ['confirm', false, PARAM_BOOL, false] + ['confirm', false, PARAM_BOOL, false], ]; } @@ -89,7 +89,7 @@ protected function pre_content() { } protected function handle_save() { - $filters = isset($_POST['filters']) ? $_POST['filters'] : array(); + $filters = isset($_POST['filters']) ? $_POST['filters'] : []; $this->userfilters = $this->save_filters($filters, $this->userfilters); } @@ -131,7 +131,7 @@ protected function get_available_rules() { 'name' => get_string('ruleset', 'block_xp'), 'info' => get_string('rulesetinfo', 'block_xp'), 'rule' => new \block_xp_ruleset(), - ] + ], ]; } @@ -234,7 +234,7 @@ public static function save_rules_filters(course_world $world, $filters, $existi $courseid = $world->get_courseid(); $filtermanager = $world->get_filter_manager(); - $filterids = array(); + $filterids = []; foreach ($filters as $filterdata) { $data = $filterdata; $data['ruledata'] = json_encode($data['rule'], true); diff --git a/classes/local/controller/visuals_controller.php b/classes/local/controller/visuals_controller.php index 90daf957..7bb66128 100644 --- a/classes/local/controller/visuals_controller.php +++ b/classes/local/controller/visuals_controller.php @@ -56,7 +56,7 @@ class visuals_controller extends page_controller { protected function define_optional_params() { return [ ['reset', false, PARAM_BOOL, false], - ['confirm', false, PARAM_BOOL, false] + ['confirm', false, PARAM_BOOL, false], ]; } @@ -75,7 +75,7 @@ final protected function get_filemanager_context() { * @return array */ final protected function get_filemanager_options() { - return ['subdirs' => 0, 'accepted_types' => array('.jpg', '.png', '.gif', '.svg')]; + return ['subdirs' => 0, 'accepted_types' => ['.jpg', '.png', '.gif', '.svg']]; } /** @@ -87,7 +87,7 @@ protected function define_form() { return new \block_xp\form\visuals($this->pageurl->out(false), [ 'showpromo' => di::get('config')->get('enablepromoincourses'), 'promourl' => $this->urlresolver->reverse('promo', ['courseid' => $this->courseid]), - 'fmoptions' => $this->get_filemanager_options() + 'fmoptions' => $this->get_filemanager_options(), ]); } @@ -144,7 +144,7 @@ protected function get_initial_form_data() { } return [ - 'badges' => $draftitemid + 'badges' => $draftitemid, ]; } diff --git a/classes/local/default_container.php b/classes/local/default_container.php index 9dec07bf..e272cf68 100644 --- a/classes/local/default_container.php +++ b/classes/local/default_container.php @@ -244,7 +244,7 @@ protected function get_config() { */ protected function get_config_locked() { return new \block_xp\local\config\mdl_locked_config('block_xp', [ - 'identitymode' + 'identitymode', ]); } diff --git a/classes/local/factory/badge_url_resolver_course_world_factory.php b/classes/local/factory/badge_url_resolver_course_world_factory.php index eb7cc992..d1aba9c6 100644 --- a/classes/local/factory/badge_url_resolver_course_world_factory.php +++ b/classes/local/factory/badge_url_resolver_course_world_factory.php @@ -25,7 +25,7 @@ namespace block_xp\local\factory; -use \block_xp\local\course_world; +use block_xp\local\course_world; /** * Badge URL resolver course world factory interface. diff --git a/classes/local/factory/course_world_leaderboard_factory.php b/classes/local/factory/course_world_leaderboard_factory.php index 48e77bcf..e21edd2e 100644 --- a/classes/local/factory/course_world_leaderboard_factory.php +++ b/classes/local/factory/course_world_leaderboard_factory.php @@ -25,7 +25,7 @@ namespace block_xp\local\factory; -use \block_xp\local\course_world; +use block_xp\local\course_world; /** * Course world leaderboard factory interface. diff --git a/classes/local/factory/course_world_leaderboard_factory_with_config.php b/classes/local/factory/course_world_leaderboard_factory_with_config.php index 5be378fc..25ce02db 100644 --- a/classes/local/factory/course_world_leaderboard_factory_with_config.php +++ b/classes/local/factory/course_world_leaderboard_factory_with_config.php @@ -26,7 +26,7 @@ namespace block_xp\local\factory; use block_xp\local\config\config; -use \block_xp\local\course_world; +use block_xp\local\course_world; /** * Course world leaderboard factory interface. diff --git a/classes/local/factory/course_world_navigation_factory.php b/classes/local/factory/course_world_navigation_factory.php index 9c9d0814..b15cba2e 100644 --- a/classes/local/factory/course_world_navigation_factory.php +++ b/classes/local/factory/course_world_navigation_factory.php @@ -25,7 +25,7 @@ namespace block_xp\local\factory; -use \block_xp\local\course_world; +use block_xp\local\course_world; /** * Course world navigation factory interface. diff --git a/classes/local/factory/default_course_world_navigation_factory.php b/classes/local/factory/default_course_world_navigation_factory.php index cdafd542..7eff5f54 100644 --- a/classes/local/factory/default_course_world_navigation_factory.php +++ b/classes/local/factory/default_course_world_navigation_factory.php @@ -97,7 +97,7 @@ protected function make_course_navigation(course_world $world) { $links[] = [ 'id' => 'infos', 'url' => $urlresolver->reverse('infos', ['courseid' => $courseid]), - 'text' => get_string('navinfos', 'block_xp') + 'text' => get_string('navinfos', 'block_xp'), ]; } @@ -113,7 +113,7 @@ protected function make_course_navigation(course_world $world) { 'id' => 'ladder', 'url' => null, 'text' => get_string('navladder', 'block_xp'), - 'children' => array_filter([$laddernav]) + 'children' => array_filter([$laddernav]), ]; $canviewlogs = $accessperms instanceof access_logs_permissions && $accessperms->can_access_logs(); @@ -144,7 +144,7 @@ protected function make_course_navigation(course_world $world) { 'children' => array_filter([ $canviewreport ? $reportnav : null, $canviewlogs ? $lognav : null, - ]) + ]), ]; } @@ -162,10 +162,10 @@ protected function make_course_navigation(course_world $world) { [ 'id' => 'visuals', 'url' => $urlresolver->reverse('visuals', ['courseid' => $courseid]), - 'text' => get_string('navvisuals', 'block_xp') + 'text' => get_string('navvisuals', 'block_xp'), ], - ] + ], ]; $links[] = [ 'id' => 'rules', @@ -182,28 +182,28 @@ protected function make_course_navigation(course_world $world) { 'id' => 'graderules', 'url' => $urlresolver->reverse('graderules', ['courseid' => $courseid]), 'text' => get_string('navgraderules', 'block_xp'), - 'addonrequired' => !$hasaddon + 'addonrequired' => !$hasaddon, ] : null, $showpromo || $hasaddon ? [ 'id' => 'drops', 'url' => $urlresolver->reverse('drops', ['courseid' => $courseid]), 'text' => get_string('navdrops', 'block_xp'), - 'addonrequired' => !$hasaddon + 'addonrequired' => !$hasaddon, ] : null, $showpromo || $hasaddon ? [ 'id' => 'import', 'url' => $urlresolver->reverse('import', ['courseid' => $courseid]), 'text' => get_string('navimport', 'block_xp'), - 'addonrequired' => !$hasaddon - ] : null - ]) + 'addonrequired' => !$hasaddon, + ] : null, + ]), ]; $links[] = [ 'id' => 'config', 'url' => $urlresolver->reverse('config', ['courseid' => $courseid]), - 'text' => get_string('navsettings', 'block_xp') + 'text' => get_string('navsettings', 'block_xp'), ]; // @codingStandardsIgnoreStart @@ -229,7 +229,7 @@ protected function make_course_navigation(course_world $world) { $links[] = [ 'id' => 'promo', 'url' => $urlresolver->reverse('promo', ['courseid' => $courseid]), - 'text' => $star . get_string('navpromo', 'block_xp') . $hasnew + 'text' => $star . get_string('navpromo', 'block_xp') . $hasnew, ]; } } diff --git a/classes/local/leaderboard/course_user_leaderboard.php b/classes/local/leaderboard/course_user_leaderboard.php index 49b841f8..5dd319d9 100644 --- a/classes/local/leaderboard/course_user_leaderboard.php +++ b/classes/local/leaderboard/course_user_leaderboard.php @@ -64,6 +64,17 @@ class course_user_leaderboard implements leaderboard { /** @var string The DB table. */ protected $table = 'block_xp'; + /** @var string SQL fields. */ + protected $fields; + /** @var string SQL from. */ + protected $from; + /** @var string SQL where. */ + protected $where; + /** @var string SQL order. */ + protected $order; + /** @var array SQL params. */ + protected $params; + /** * Constructor. * @@ -184,7 +195,7 @@ protected function get_position_with_xp($id, $xp) { $params = $this->params + [ 'posxp' => $xp, 'posxpeq' => $xp, - 'posid' => $id + 'posid' => $id, ]; return $this->db->count_records_sql($sql, $params); } diff --git a/classes/local/logger/course_user_event_collection_logger.php b/classes/local/logger/course_user_event_collection_logger.php index 08897019..3baa0ee6 100644 --- a/classes/local/logger/course_user_event_collection_logger.php +++ b/classes/local/logger/course_user_event_collection_logger.php @@ -75,7 +75,7 @@ public function delete_older_than(DateTime $dt) { 'courseid = :courseid AND time < :time', [ 'courseid' => $this->courseid, - 'time' => $dt->getTimestamp() + 'time' => $dt->getTimestamp(), ] ); } @@ -128,7 +128,7 @@ public function reset() { static::TABLE, 'courseid = :courseid', [ - 'courseid' => $this->courseid + 'courseid' => $this->courseid, ] ); } @@ -151,7 +151,7 @@ public function reset_by_group($groupid) { $params = [ 'courseid' => $this->courseid, - 'groupid' => $groupid + 'groupid' => $groupid, ]; $this->db->execute($sql, $params); @@ -168,7 +168,7 @@ public function reset_by_id($id) { static::TABLE, [ 'courseid' => $this->courseid, - 'userid' => $id + 'userid' => $id, ] ); } diff --git a/classes/local/logger/global_collection_logger.php b/classes/local/logger/global_collection_logger.php index a532b6a0..9177b735 100644 --- a/classes/local/logger/global_collection_logger.php +++ b/classes/local/logger/global_collection_logger.php @@ -70,7 +70,7 @@ public function delete_older_than(DateTime $dt) { static::TABLE, 'time < :time', [ - 'time' => $dt->getTimestamp() + 'time' => $dt->getTimestamp(), ] ); } diff --git a/classes/local/notification/course_level_up_notification_service.php b/classes/local/notification/course_level_up_notification_service.php index bba2bce1..89488fb3 100644 --- a/classes/local/notification/course_level_up_notification_service.php +++ b/classes/local/notification/course_level_up_notification_service.php @@ -38,6 +38,9 @@ class course_level_up_notification_service { /** User preference prefix. */ const USERPREF_NOTIFY = 'block_xp_notify_level_up_'; + /** @var string The key. */ + protected $key; + /** * Constructor. * diff --git a/classes/local/observer/default_observer_rules_maker.php b/classes/local/observer/default_observer_rules_maker.php index 3c24d919..dd140c93 100644 --- a/classes/local/observer/default_observer_rules_maker.php +++ b/classes/local/observer/default_observer_rules_maker.php @@ -43,12 +43,12 @@ public function get_observer_rules() { [ 'eventname' => '*', 'callback' => 'block_xp\\local\\observer\\observer::catch_all', - 'internal' => false + 'internal' => false, ], [ 'eventname' => '\\core\\event\\course_deleted', - 'callback' => 'block_xp\\local\\observer\\observer::course_deleted' - ] + 'callback' => 'block_xp\\local\\observer\\observer::course_deleted', + ], ]; } diff --git a/classes/local/observer/default_state_store_observer.php b/classes/local/observer/default_state_store_observer.php index 2dede4fb..19b5f9d5 100644 --- a/classes/local/observer/default_state_store_observer.php +++ b/classes/local/observer/default_state_store_observer.php @@ -87,8 +87,8 @@ public function leveled_up(state_store $store, $id, level $beforelevel, level $a 'context' => $this->context, 'relateduserid' => $id, 'other' => [ - 'level' => $i - ] + 'level' => $i, + ], ]; $lupevent = \block_xp\event\user_leveledup::create($params); $lupevent->trigger(); diff --git a/classes/local/observer/observer.php b/classes/local/observer/observer.php index c736d49c..ef0723cf 100644 --- a/classes/local/observer/observer.php +++ b/classes/local/observer/observer.php @@ -45,7 +45,7 @@ public static function course_deleted(\core\event\course_deleted $event) { $courseid = $event->objectid; // Clean up the data that could be left behind. - $conditions = array('courseid' => $courseid); + $conditions = ['courseid' => $courseid]; $DB->delete_records('block_xp', $conditions); $DB->delete_records('block_xp_config', $conditions); $DB->delete_records('block_xp_filters', $conditions); @@ -54,10 +54,10 @@ public static function course_deleted(\core\event\course_deleted $event) { // Flags. Note that this is based on the actually implementation. $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, ]); // Delete the files. diff --git a/classes/local/reason/event_name_reason.php b/classes/local/reason/event_name_reason.php index 13924fd2..15707082 100644 --- a/classes/local/reason/event_name_reason.php +++ b/classes/local/reason/event_name_reason.php @@ -35,6 +35,9 @@ */ class event_name_reason implements reason { + /** @var string The event name. */ + protected $eventname; + /** * Constructor. * diff --git a/classes/local/routing/ajax_routes_config.php b/classes/local/routing/ajax_routes_config.php index 5e9ad802..3ab495f1 100644 --- a/classes/local/routing/ajax_routes_config.php +++ b/classes/local/routing/ajax_routes_config.php @@ -46,7 +46,7 @@ public function __construct() { '~^/notice/([a-z0-9_-]+)/dismiss$~', 'ajax_notice_dismiss', [ - 1 => 'name' + 1 => 'name', ] ), ]); diff --git a/classes/local/routing/default_routes_config.php b/classes/local/routing/default_routes_config.php index 0eeee9b3..9305ff84 100644 --- a/classes/local/routing/default_routes_config.php +++ b/classes/local/routing/default_routes_config.php @@ -52,7 +52,7 @@ public function __construct() { '~^/config/(\d+)$~', 'config', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -61,7 +61,7 @@ public function __construct() { '~^/infos/(\d+)$~', 'infos', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -70,7 +70,7 @@ public function __construct() { '~^/ladder/(\d+)$~', 'ladder', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -79,7 +79,7 @@ public function __construct() { '~^/levels/(\d+)$~', 'levels', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -88,7 +88,7 @@ public function __construct() { '~^/log/(\d+)$~', 'log', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -97,7 +97,7 @@ public function __construct() { '~^/report/(\d+)$~', 'report', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -106,7 +106,7 @@ public function __construct() { '~^/rules/(\d+)$~', 'rules', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -115,7 +115,7 @@ public function __construct() { '~^/graderules/(\d+)$~', 'grade_rules', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -124,7 +124,7 @@ public function __construct() { '~^/drops/(\d+)$~', 'drops', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -133,7 +133,7 @@ public function __construct() { '~^/import/(\d+)$~', 'import', [ - 1 => 'courseid' + 1 => 'courseid', ] ), new route_definition( @@ -142,7 +142,7 @@ public function __construct() { '~^/visuals/(\d+)$~', 'visuals', [ - 1 => 'courseid' + 1 => 'courseid', ] ), @@ -185,7 +185,7 @@ public function __construct() { '~^/promo/(\d+)$~', 'promo', [ - 1 => 'courseid' + 1 => 'courseid', ] ), ]; diff --git a/classes/local/routing/route_definition.php b/classes/local/routing/route_definition.php index 5b230cf2..a2322e63 100644 --- a/classes/local/routing/route_definition.php +++ b/classes/local/routing/route_definition.php @@ -35,6 +35,17 @@ */ class route_definition { + /** @var string The route name. */ + protected $name; + /** @var string The route URL. */ + protected $url; + /** @var string The regex. */ + protected $regex; + /** @var string The controller name. */ + protected $controllername; + /** @var array The mappings. */ + protected $mapping; + /** * Constructor. * diff --git a/classes/local/rule/event_lister.php b/classes/local/rule/event_lister.php index 0a3feb11..3b068d2e 100644 --- a/classes/local/rule/event_lister.php +++ b/classes/local/rule/event_lister.php @@ -46,6 +46,8 @@ class event_lister { /** @var cache The cache store. */ protected $cache; + /** @var bool Whether is used site site. */ + protected $forwholesite; /** * Constructor. @@ -73,12 +75,12 @@ protected function construct_events_list() { if ($infos) { $carry[$infos['eventname']] = get_string('colon', 'block_xp', (object) [ 'a' => $prefix, - 'b' => $infos['name'] + 'b' => $infos['name'], ]); } return $carry; }, [])); - }, [])]; + }, []), ]; // Get module events. $list = array_merge($list, self::get_events_list_from_plugintype('mod')); @@ -97,7 +99,7 @@ protected function get_core_events() { // Add some system events. $eventclasses = [get_string('course') => [ '\\core\\event\\course_viewed', - ]]; + ], ]; return $eventclasses; } @@ -239,7 +241,7 @@ protected static function get_events_list_from_plugin($component) { $carry[$infos['eventname']] = get_string('colon', 'block_xp', [ 'a' => $plugininfo->displayname, - 'b' => $infos['name'] + 'b' => $infos['name'], ]); return $carry; }, []); @@ -269,7 +271,7 @@ protected static function get_events_list_from_plugintype($plugintype) { if (!empty($events)) { $pluginmanager = core_plugin_manager::instance(); $plugininfo = $pluginmanager->get_plugin_info($component); - $list[] = array($plugininfo->displayname => $events); + $list[] = [$plugininfo->displayname => $events]; } } diff --git a/classes/local/serializer/level_serializer.php b/classes/local/serializer/level_serializer.php index b305ccbf..a79ce07e 100644 --- a/classes/local/serializer/level_serializer.php +++ b/classes/local/serializer/level_serializer.php @@ -66,7 +66,7 @@ public function serialize($level) { 'xprequired' => $level->get_xp_required(), 'badgeurl' => $url ? $this->urlserializer->serialize($url) : $url, 'name' => $level instanceof level_with_name ? $level->get_name() : null, - 'description' => $level instanceof level_with_description ? $level->get_description() : null + 'description' => $level instanceof level_with_description ? $level->get_description() : null, ]; } diff --git a/classes/local/serializer/levels_info_serializer.php b/classes/local/serializer/levels_info_serializer.php index 363fa284..1f555a5b 100644 --- a/classes/local/serializer/levels_info_serializer.php +++ b/classes/local/serializer/levels_info_serializer.php @@ -68,7 +68,7 @@ public function serialize($info) { 'coef' => $info->get_coef(), 'incr' => $info->get_incr(), 'method' => $info->get_method(), - ] : null + ] : null, ]; } @@ -91,7 +91,7 @@ public function get_read_structure($required = VALUE_REQUIRED, $default = null, 'base' => new external_value(PARAM_INT), 'coef' => new external_value(PARAM_FLOAT), 'incr' => new external_value(PARAM_INT), - ], VALUE_OPTIONAL, null) + ], VALUE_OPTIONAL, null), ], '', $required, $default); } diff --git a/classes/local/setting/compatibility_check_setting.php b/classes/local/setting/compatibility_check_setting.php index 3fdec224..a3efdcab 100644 --- a/classes/local/setting/compatibility_check_setting.php +++ b/classes/local/setting/compatibility_check_setting.php @@ -68,7 +68,7 @@ protected function get_html_content() { 'title' => get_string('potentialmoodleincompatibility', 'block_xp'), 'message' => get_string('pluginxmaybeincompatible', 'block_xp', ['name' => 'Level Up XP', 'component' => 'block_xp', 'version' => $humanbranch]), - 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#potential-moodle-incompatibility' + 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#potential-moodle-incompatibility', ]; } if ($localxp && (empty($localxp->pluginsupported) || ($CFG->branch < $localxp->pluginsupported[0] @@ -77,7 +77,7 @@ protected function get_html_content() { 'title' => get_string('potentialmoodleincompatibility', 'block_xp'), 'message' => get_string('pluginxmaybeincompatible', 'block_xp', ['name' => 'Level Up XP+', 'component' => 'local_xp', 'version' => $humanbranch]), - 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#potential-moodle-incompatibility' + 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#potential-moodle-incompatibility', ]; } } @@ -86,19 +86,19 @@ protected function get_html_content() { $messages[] = [ 'title' => get_string('outofsyncexcessive', 'block_xp'), 'message' => get_string('outofsyncexcessiveinfo', 'block_xp'), - 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#out-of-sync' + 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#out-of-sync', ]; } else if ($addon->is_out_of_sync()) { $messages[] = [ 'title' => get_string('outofsync', 'block_xp'), 'message' => get_string('outofsyncinfo', 'block_xp'), - 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#out-of-sync' + 'url' => 'https://docs.levelup.plus/docs/xp/requirements-compatibility#out-of-sync', ]; } return di::get('renderer')->render_from_template('block_xp/admin-compatibility-check', [ 'haswarnings' => !empty($messages), - 'warnings' => $messages + 'warnings' => $messages, ]); } diff --git a/classes/local/setting/default_settings_maker.php b/classes/local/setting/default_settings_maker.php index 34b39c4b..8032b57a 100644 --- a/classes/local/setting/default_settings_maker.php +++ b/classes/local/setting/default_settings_maker.php @@ -159,7 +159,7 @@ protected function get_general_settings() { $this->defaults->get('context'), [ CONTEXT_COURSE => get_string('incourses', 'block_xp'), - CONTEXT_SYSTEM => get_string('forthewholesite', 'block_xp') + CONTEXT_SYSTEM => get_string('forthewholesite', 'block_xp'), ] )); @@ -233,7 +233,7 @@ protected function get_default_settings() { $url = $this->urlresolver->reverse('config', ['courseid' => SITEID]); return di::get('renderer')->notification_without_close(strip_tags( markdown_to_html(get_string('editingdefaultsettingsinwholesitemodenotice', 'block_xp', [ - 'url' => $url->out(false) + 'url' => $url->out(false), ])), '' ), \core\output\notification::NOTIFY_WARNING); @@ -346,7 +346,7 @@ protected function get_default_settings() { get_string('configblockrankingsnapshot', 'block_xp'), get_string('configblockrankingsnapshot_help', 'block_xp'), $defaults['blockrankingsnapshot'], [ 0 => get_string('no'), - 1 => get_string('yes') + 1 => get_string('yes'), ])); // Block recent activity. @@ -354,7 +354,7 @@ protected function get_default_settings() { get_string('configrecentactivity', 'block_xp'), get_string('configrecentactivity_help', 'block_xp'), $defaults['blockrecentactivity'], [ 0 => get_string('no'), - 3 => get_string('yes') + 3 => get_string('yes'), ])); return $settings; diff --git a/classes/local/setting/recommended_plugins_setting.php b/classes/local/setting/recommended_plugins_setting.php index e8d6e3ad..470a184b 100644 --- a/classes/local/setting/recommended_plugins_setting.php +++ b/classes/local/setting/recommended_plugins_setting.php @@ -66,7 +66,7 @@ protected function get_html_content() { 'component' => 'availability_xp', 'name' => 'Level Up XP Availability', 'description' => get_string('pluginavailabilityxpdesc', 'block_xp'), - 'url' => new moodle_url('https://moodle.org/plugins/availability_xp') + 'url' => new moodle_url('https://moodle.org/plugins/availability_xp'), ], [ 'component' => 'enrol_xp', @@ -79,7 +79,7 @@ protected function get_html_content() { 'name' => 'Shortcodes', 'description' => get_string('pluginshortcodesdesc', 'block_xp'), 'url' => new moodle_url('https://moodle.org/plugins/filter_shortcodes'), - ] + ], ]); return di::get('renderer')->render_from_template('block_xp/admin-recommended-plugins', ['plugins' => $plugins]); diff --git a/classes/local/shortcode/default_shortcodes_definition_maker.php b/classes/local/shortcode/default_shortcodes_definition_maker.php index d1269d29..f9dc9ef7 100644 --- a/classes/local/shortcode/default_shortcodes_definition_maker.php +++ b/classes/local/shortcode/default_shortcodes_definition_maker.php @@ -44,28 +44,28 @@ public function get_shortcodes_definition() { return [ 'xpbadge' => [ 'callback' => 'block_xp\local\shortcode\handler::xpbadge', - 'description' => 'shortcode:xpbadge' + 'description' => 'shortcode:xpbadge', ], 'xpiflevel' => [ 'callback' => 'block_xp\local\shortcode\handler::xpiflevel', 'description' => 'shortcode:xpiflevel', - 'wraps' => true + 'wraps' => true, ], 'xpladder' => [ 'callback' => 'block_xp\local\shortcode\handler::xpladder', - 'description' => 'shortcode:xpladder' + 'description' => 'shortcode:xpladder', ], 'xplevelname' => [ 'callback' => 'block_xp\local\shortcode\handler::xplevelname', - 'description' => 'shortcode:xplevelname' + 'description' => 'shortcode:xplevelname', ], 'xppoints' => [ 'callback' => 'block_xp\local\shortcode\handler::xppoints', - 'description' => 'shortcode:xppoints' + 'description' => 'shortcode:xppoints', ], 'xpprogressbar' => [ 'callback' => 'block_xp\local\shortcode\handler::xpprogressbar', - 'description' => 'shortcode:xpprogressbar' + 'description' => 'shortcode:xpprogressbar', ], ]; } diff --git a/classes/local/shortcode/handler.php b/classes/local/shortcode/handler.php index 31ed90ff..a770fcda 100644 --- a/classes/local/shortcode/handler.php +++ b/classes/local/shortcode/handler.php @@ -145,7 +145,7 @@ public static function xpiflevel($shortcode, $args, $content, $env, $next) { // Attributes can be HTML encoded. $args = array_combine(array_map(function($key) { - return html_entity_decode($key); + return html_entity_decode($key, ENT_COMPAT | ENT_HTML401); }, array_keys($args)), array_values($args)); // The user types <=3, so they are stored in the < key. diff --git a/classes/local/sql/limit.php b/classes/local/sql/limit.php index 0669be47..4579b3ac 100644 --- a/classes/local/sql/limit.php +++ b/classes/local/sql/limit.php @@ -35,6 +35,11 @@ */ class limit { + /** @var int The count. */ + protected $count; + /** @var int The offset. */ + protected $offset; + /** * Constructor. * diff --git a/classes/local/strategy/global_collection_strategy.php b/classes/local/strategy/global_collection_strategy.php index 9f36a1e7..5894b146 100644 --- a/classes/local/strategy/global_collection_strategy.php +++ b/classes/local/strategy/global_collection_strategy.php @@ -50,7 +50,7 @@ class global_collection_strategy implements event_collection_strategy { * @param int $contextmode The context mode. */ public function __construct(course_world_factory $worldfactory, $contextmode) { - $allowedcontexts = array(CONTEXT_COURSE, CONTEXT_MODULE); + $allowedcontexts = [CONTEXT_COURSE, CONTEXT_MODULE]; if (!empty($contextmode) && $contextmode == CONTEXT_SYSTEM) { $allowedcontexts[] = CONTEXT_SYSTEM; } diff --git a/classes/local/task/default_tasks_definition_maker.php b/classes/local/task/default_tasks_definition_maker.php index fd44938a..530bea99 100644 --- a/classes/local/task/default_tasks_definition_maker.php +++ b/classes/local/task/default_tasks_definition_maker.php @@ -47,7 +47,7 @@ public function get_tasks_definition() { 'hour' => 3, 'day' => '*', 'dayofweek' => '*', - 'month' => '*' + 'month' => '*', ], [ 'classname' => 'block_xp\task\usage_report', @@ -56,8 +56,8 @@ public function get_tasks_definition() { 'hour' => 'R', 'day' => '*', 'dayofweek' => 'R', - 'month' => '*' - ] + 'month' => '*', + ], ]; } diff --git a/classes/local/xp/admin_filter_manager.php b/classes/local/xp/admin_filter_manager.php index e8b43f44..df8bb897 100644 --- a/classes/local/xp/admin_filter_manager.php +++ b/classes/local/xp/admin_filter_manager.php @@ -98,22 +98,22 @@ protected function get_default_filters($category = \block_xp_filter::CATEGORY_EV $as = new \block_xp_rule_property(\block_xp_rule_base::CT, 'assessable_submitted', 'eventname'); $au = new \block_xp_rule_property(\block_xp_rule_base::CT, 'assessable_uploaded', 'eventname'); - $list = array(); + $list = []; - $ruleset = new \block_xp_ruleset(array($bcmv, $dsc, $sc, $as, $au), \block_xp_ruleset::ANY); - $data = array('rule' => $ruleset, 'points' => 0); + $ruleset = new \block_xp_ruleset([$bcmv, $dsc, $sc, $as, $au], \block_xp_ruleset::ANY); + $data = ['rule' => $ruleset, 'points' => 0]; $list[] = \block_xp_filter::load_from_data($data); - $data = array('rule' => $c, 'points' => 45); + $data = ['rule' => $c, 'points' => 45]; $list[] = \block_xp_filter::load_from_data($data); - $data = array('rule' => $r, 'points' => 9); + $data = ['rule' => $r, 'points' => 9]; $list[] = \block_xp_filter::load_from_data($data); - $data = array('rule' => $u, 'points' => 3); + $data = ['rule' => $u, 'points' => 3]; $list[] = \block_xp_filter::load_from_data($data); - $data = array('rule' => $d, 'points' => 0); + $data = ['rule' => $d, 'points' => 0]; $list[] = \block_xp_filter::load_from_data($data); return $list; } @@ -188,7 +188,7 @@ public function reset_all_courses_to_defaults() { // This is dangerously hardcoded, byt let's use this for now to detect all instances to work on. $sql = 'courseid > 0 AND defaultfilters != :defaultfilters'; $courseids = $this->db->get_fieldset_select('block_xp_config', 'courseid', $sql, [ - 'defaultfilters' => course_world_config::DEFAULT_FILTERS_MISSING + 'defaultfilters' => course_world_config::DEFAULT_FILTERS_MISSING, ]); // This is slow, but that's sort of the cleanest way. diff --git a/classes/local/xp/course_filter_manager.php b/classes/local/xp/course_filter_manager.php index 0ff97b6b..e0fed835 100644 --- a/classes/local/xp/course_filter_manager.php +++ b/classes/local/xp/course_filter_manager.php @@ -168,8 +168,8 @@ public function get_static_filters() { */ public function get_user_filters($category = \block_xp_filter::CATEGORY_EVENTS) { $results = $this->db->get_recordset('block_xp_filters', ['courseid' => $this->courseid, - 'category' => $category], 'sortorder ASC, id ASC'); - $filters = array(); + 'category' => $category, ], 'sortorder ASC, id ASC'); + $filters = []; foreach ($results as $key => $filter) { $filters[$filter->id] = \block_xp_filter::load_from_data($filter); } diff --git a/classes/local/xp/course_user_state_store.php b/classes/local/xp/course_user_state_store.php index a107e344..91231db0 100644 --- a/classes/local/xp/course_user_state_store.php +++ b/classes/local/xp/course_user_state_store.php @@ -111,7 +111,7 @@ public function get_state($id) { $params = [ 'contextlevel' => CONTEXT_USER, 'courseid' => $this->courseid, - 'userid' => $id + 'userid' => $id, ]; return $this->make_state_from_record($this->db->get_record_sql($sql, $params, MUST_EXIST)); @@ -168,7 +168,7 @@ public function increase($id, $amount) { $params = [ 'xp' => $amount, 'courseid' => $this->courseid, - 'userid' => $id + 'userid' => $id, ]; $this->db->execute($sql, $params); } else { @@ -301,7 +301,7 @@ public function reset_by_group($groupid) { $params = [ 'courseid' => $this->courseid, - 'groupid' => $groupid + 'groupid' => $groupid, ]; $this->db->execute($sql, $params); @@ -332,7 +332,7 @@ public function set($id, $amount) { $params = [ 'xp' => $amount, 'courseid' => $this->courseid, - 'userid' => $id + 'userid' => $id, ]; $this->db->execute($sql, $params); } else { diff --git a/classes/local/xp/levels_info_writer.php b/classes/local/xp/levels_info_writer.php index 4f84967d..ce87faa4 100644 --- a/classes/local/xp/levels_info_writer.php +++ b/classes/local/xp/levels_info_writer.php @@ -206,7 +206,7 @@ protected function deconstruct_finaldata($data) { return [ 'points' => array_values($data['xp']), // Forced indexation at zero as it wasn't the case previously. 'algo' => $algo, - 'metadata' => $metadata + 'metadata' => $metadata, ]; } @@ -369,7 +369,7 @@ protected function validate_raw_data($rawdata) { 'base' => new external_value(PARAM_INT), 'incr' => new external_value(PARAM_INT), 'coef' => new external_value(PARAM_FLOAT), - ], '', VALUE_OPTIONAL, null) + ], '', VALUE_OPTIONAL, null), ]); $data = external_api::validate_parameters($structure, $rawdata); diff --git a/classes/local/xp/state_rank.php b/classes/local/xp/state_rank.php index e54751e8..11f9bd05 100644 --- a/classes/local/xp/state_rank.php +++ b/classes/local/xp/state_rank.php @@ -35,6 +35,11 @@ */ class state_rank implements rank { + /** @var int The rank. */ + protected $rank; + /** @var state The state. */ + protected $state; + /** * Constructor. * diff --git a/classes/output/leaderboard_table.php b/classes/output/leaderboard_table.php index a8777543..10d0ebce 100644 --- a/classes/output/leaderboard_table.php +++ b/classes/output/leaderboard_table.php @@ -71,6 +71,9 @@ class leaderboard_table extends flexible_table { /** @var bool Whether to show the pagesize selector. */ protected $showpagesizeselector = false; + /** @var limit The fence. */ + protected $fence; + /** * Constructor. * @@ -274,7 +277,7 @@ public function start_html() { } $this->wrap_html_start(); - echo html_writer::start_tag('div', array('class' => 'no-overflow')); + echo html_writer::start_tag('div', ['class' => 'no-overflow']); echo html_writer::start_tag('table', $this->attributes); } @@ -356,7 +359,7 @@ public function print_nothing_to_display() { protected function rank_to_keyed_data($rank) { $row = (object) [ 'rank' => $rank->get_rank(), - 'state' => $rank->get_state() + 'state' => $rank->get_state(), ]; return [ 'fullname' => $this->col_fullname($row), diff --git a/classes/output/log_table.php b/classes/output/log_table.php index 92276685..42808849 100644 --- a/classes/output/log_table.php +++ b/classes/output/log_table.php @@ -71,22 +71,22 @@ public function __construct(course_world $world, $groupid, $userid = null) { $courseid = $world->get_courseid(); // Define columns. - $this->define_columns(array( + $this->define_columns([ 'time', 'fullname', 'xp', - 'eventname' - )); - $this->define_headers(array( + 'eventname', + ]); + $this->define_headers([ get_string('eventtime', 'block_xp'), get_string('fullname'), get_string('reward', 'block_xp'), - get_string('eventname', 'block_xp') - )); + get_string('eventname', 'block_xp'), + ]); // Define SQL. $sqlfrom = ''; - $sqlparams = array(); + $sqlparams = []; if ($groupid) { $sqlfrom = '{block_xp_log} x JOIN {groups_members} gm @@ -94,7 +94,7 @@ public function __construct(course_world $world, $groupid, $userid = null) { AND gm.userid = x.userid LEFT JOIN {user} u ON x.userid = u.id'; - $sqlparams = array('groupid' => $groupid); + $sqlparams = ['groupid' => $groupid]; } else { $sqlfrom = '{block_xp_log} x LEFT JOIN {user} u ON x.userid = u.id'; } @@ -104,7 +104,7 @@ public function __construct(course_world $world, $groupid, $userid = null) { $this->sql->fields = 'x.*, ' . user_utils::name_fields('u'); $this->sql->from = $sqlfrom; $this->sql->where = 'courseid = :courseid'; - $this->sql->params = array_merge(array('courseid' => $courseid), $sqlparams); + $this->sql->params = array_merge(['courseid' => $courseid], $sqlparams); if ($this->filterbyuserid) { $this->sql->where .= ' AND userid = :userid'; $this->sql->params = array_merge($this->sql->params, ['userid' => $this->filterbyuserid]); diff --git a/classes/output/report_table.php b/classes/output/report_table.php index ffa3b127..d51d6c1f 100644 --- a/classes/output/report_table.php +++ b/classes/output/report_table.php @@ -147,7 +147,7 @@ protected function init_sql() { // are not a member of the group though. if (empty($groupid)) { $sql = 'SELECT userid FROM {block_xp} WHERE courseid = :courseid'; - $params = array('courseid' => $courseid); + $params = ['courseid' => $courseid]; } else { $sql = 'SELECT b.userid FROM {block_xp} b @@ -155,7 +155,7 @@ protected function init_sql() { ON b.userid = gm.userid AND gm.groupid = :groupid WHERE courseid = :courseid'; - $params = array('courseid' => $courseid, 'groupid' => $groupid); + $params = ['courseid' => $courseid, 'groupid' => $groupid]; } $entries = $this->db->get_recordset_sql($sql, $params); foreach ($entries as $entry) { @@ -175,10 +175,10 @@ protected function init_sql() { LEFT JOIN {block_xp} x ON (x.userid = u.id AND x.courseid = :courseid)"; $this->sql->where = "u.id $insql"; - $this->sql->params = array_merge($inparams, array( + $this->sql->params = array_merge($inparams, [ 'courseid' => $courseid, - 'contextlevel' => CONTEXT_USER - )); + 'contextlevel' => CONTEXT_USER, + ]); } /** diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index e0e906c2..dbebe218 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -361,10 +361,10 @@ protected static function delete_preferences_for_all_users_in_context(context $c $db = \block_xp\di::get('db'); $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, ]); } @@ -481,7 +481,7 @@ protected static function get_preferences_for_user($userid) { $prefs[] = (object) [ 'name' => $name, 'value' => $value, - 'description' => $desc + 'description' => $desc, ]; } diff --git a/classes/rule.php b/classes/rule.php index 9b4fc3c7..e5bd1c39 100644 --- a/classes/rule.php +++ b/classes/rule.php @@ -69,8 +69,8 @@ abstract public function get_description(); * @return string */ public function get_form($basename) { - return html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $basename . '[_class]', - 'value' => get_class($this))); + return html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $basename . '[_class]', + 'value' => get_class($this), ]); } /** @@ -98,7 +98,7 @@ protected function get_renderer() { * @return array Keys are properties, values are the values. */ public function export() { - return array('_class' => get_class($this)); + return ['_class' => get_class($this)]; } /** diff --git a/classes/rule_base.php b/classes/rule_base.php index 93e2adf3..a8007fd6 100644 --- a/classes/rule_base.php +++ b/classes/rule_base.php @@ -100,10 +100,10 @@ public function export() { * @return string */ protected function get_compare_select($basename) { - return html_writer::select(array( + return html_writer::select([ self::CT => get_string('rule:' . self::CT, 'block_xp'), - self::EQ => get_string('rule:' . self::EQ, 'block_xp') - ), $basename . '[compare]', $this->compare, '', array('id' => '', 'class' => '')); + self::EQ => get_string('rule:' . self::EQ, 'block_xp'), + ], $basename . '[compare]', $this->compare, '', ['id' => '', 'class' => '']); } /** diff --git a/classes/rule_cm.php b/classes/rule_cm.php index d0a1a50c..d24a9ce5 100644 --- a/classes/rule_cm.php +++ b/classes/rule_cm.php @@ -135,7 +135,7 @@ protected function get_advanced_form($basename) { 'name' => $basename . '[value]', 'class' => 'cm-rule-contextid', 'type' => 'hidden', - 'value' => $this->value + 'value' => $this->value, ]); if (!$hascm) { @@ -167,20 +167,20 @@ protected function get_advanced_form($basename) { protected function get_simple_form($basename) { global $COURSE; $output = \block_xp\di::get('renderer'); - $options = array(); + $options = []; $valuefound = empty($this->value); $modinfo = get_fast_modinfo($this->courseid); $courseformat = course_get_format($this->courseid); foreach ($modinfo->get_sections() as $sectionnum => $cmids) { - $modules = array(); + $modules = []; foreach ($cmids as $cmid) { $cm = $modinfo->get_cm($cmid); $modules[$cm->context->id] = $cm->name; $valuefound = $valuefound || $this->value == $cm->context->id; } - $options[] = array($courseformat->get_section_name($sectionnum) => $modules); + $options[] = [$courseformat->get_section_name($sectionnum) => $modules]; } if (!$valuefound) { @@ -188,7 +188,7 @@ protected function get_simple_form($basename) { } $o = block_xp_rule::get_form($basename); - $modules = html_writer::select($options, $basename . '[value]', $this->value, '', array('id' => '', 'class' => '')); + $modules = html_writer::select($options, $basename . '[value]', $this->value, '', ['id' => '', 'class' => '']); $helpicon = $output->help_icon('rulecm', 'block_xp'); $o .= html_writer::start_div('xp-flex xp-gap-1 xp-min-full'); diff --git a/classes/rule_event.php b/classes/rule_event.php index d54344e0..cd895a8e 100644 --- a/classes/rule_event.php +++ b/classes/rule_event.php @@ -71,7 +71,7 @@ public function get_description() { } $name = get_string('colon', 'block_xp', (object) [ 'a' => $displayname, - 'b' => $infos['name'] + 'b' => $infos['name'], ]); } else { $name = get_string('unknowneventa', 'block_xp', $this->value); @@ -116,7 +116,7 @@ public function get_form($basename) { } $modules = html_writer::select($eventslist, $basename . '[value]', $this->value, '', - array('id' => '', 'class' => '')); + ['id' => '', 'class' => '']); $o .= html_writer::start_div('xp-flex xp-gap-1'); $o .= html_writer::start_div('xp-flex xp-items-center'); diff --git a/classes/rule_property.php b/classes/rule_property.php index 31c81b87..a00dfd51 100644 --- a/classes/rule_property.php +++ b/classes/rule_property.php @@ -62,11 +62,11 @@ public function __construct($compare = self::EQ, $value = '', $property = '') { * @return string */ public function get_description() { - return get_string('rulepropertydesc', 'block_xp', (object)array( + return get_string('rulepropertydesc', 'block_xp', (object)[ 'property' => $this->property, 'compare' => get_string('rule:' . $this->compare, 'block_xp'), - 'value' => $this->value - )); + 'value' => $this->value, + ]); } /** @@ -80,13 +80,13 @@ public function get_form($basename) { $o .= html_writer::start_div('xp-flex xp-gap-1'); $o .= html_writer::start_div('xp-min-w-px'); - $o .= html_writer::select(array( + $o .= html_writer::select([ 'eventname' => get_string('property:eventname', 'block_xp'), 'component' => get_string('property:component', 'block_xp'), 'action' => get_string('property:action', 'block_xp'), 'target' => get_string('property:target', 'block_xp'), 'crud' => get_string('property:crud', 'block_xp'), - ), $basename . '[property]', $this->property, '', array('id' => '', 'class' => '')); + ], $basename . '[property]', $this->property, '', ['id' => '', 'class' => '']); $o .= html_writer::end_div(); $o .= html_writer::start_div('xp-min-w-px'); @@ -94,8 +94,8 @@ public function get_form($basename) { $o .= html_writer::end_div(); $o .= html_writer::start_div('xp-min-w-px'); - $o .= html_writer::empty_tag('input', array('type' => 'text', 'name' => $basename . '[value]', - 'value' => s($this->value), 'class' => 'form-control block_xp-form-control-inline')); + $o .= html_writer::empty_tag('input', ['type' => 'text', 'name' => $basename . '[value]', + 'value' => s($this->value), 'class' => 'form-control block_xp-form-control-inline', ]); $o .= html_writer::end_div(); $o .= html_writer::end_div(); diff --git a/classes/ruleset.php b/classes/ruleset.php index e853dc04..8473e7ba 100644 --- a/classes/ruleset.php +++ b/classes/ruleset.php @@ -52,9 +52,9 @@ class block_xp_ruleset extends block_xp_rule { * * Those must implement the interface block_xp_rule. * - * @var string + * @var array */ - protected $rules = array(); + protected $rules = []; /** * Constructor. @@ -68,7 +68,7 @@ class block_xp_ruleset extends block_xp_rule { * @param array $rules The rules to add in this set. * @param string $method The method. */ - public function __construct(array $rules = array(), $method = self::ANY) { + public function __construct(array $rules = [], $method = self::ANY) { $this->rules = $rules; $this->method = $method; } @@ -99,11 +99,11 @@ public function get_description() { */ public function get_form($basename) { $o = parent::get_form($basename); - $o .= html_writer::select(array( + $o .= html_writer::select([ self::ALL => get_string('ruleset:all', 'block_xp'), self::ANY => get_string('ruleset:any', 'block_xp'), self::NONE => get_string('ruleset:none', 'block_xp'), - ), $basename . '[method]', $this->method, '', array('class' => '', 'id' => '')); + ], $basename . '[method]', $this->method, '', ['class' => '', 'id' => '']); return $o; } @@ -124,7 +124,7 @@ public function get_rules() { public function export() { $properties = parent::export(); $properties['method'] = $this->method; - $properties['rules'] = array(); + $properties['rules'] = []; foreach ($this->rules as $rule) { $properties['rules'][] = $rule->export(); } @@ -139,7 +139,7 @@ public function export() { */ protected function import(array $properties) { if (isset($properties['rules'])) { - $ruleslist = array(); + $ruleslist = []; foreach ($properties['rules'] as $rule) { $ruleobject = block_xp_rule::create($rule); if ($ruleobject) { diff --git a/db/access.php b/db/access.php index 0df6a285..07634c5c 100644 --- a/db/access.php +++ b/db/access.php @@ -24,76 +24,76 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ // Whether or not the user can add the block. - 'block/xp:addinstance' => array( + 'block/xp:addinstance' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/site:manageblocks' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/site:manageblocks', + ], // Whether or not the user can manage all aspects of the block. - 'block/xp:manage' => array( + 'block/xp:manage' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'block/xp:addinstance' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'block/xp:addinstance', + ], // Whether or not a user can earn experience point. - 'block/xp:earnxp' => array( + 'block/xp:earnxp' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( - 'student' => CAP_ALLOW - ), - ), + 'archetypes' => [ + 'student' => CAP_ALLOW, + ], + ], // Whether or not the user can add the block on their dashboard. // We don't allow anyone to add it, the teacher/manager should add it // to their default dashboards. - 'block/xp:myaddinstance' => array( + 'block/xp:myaddinstance' => [ 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array() - ), + 'archetypes' => [], + ], // Whether or not a user can see the block. - 'block/xp:view' => array( + 'block/xp:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( - 'user' => CAP_ALLOW - ), - ), + 'archetypes' => [ + 'user' => CAP_ALLOW, + ], + ], // Whether or not a user can see the logs. - 'block/xp:viewlogs' => array( + 'block/xp:viewlogs' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'block/xp:manage' - ), + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'block/xp:manage', + ], // Whether or not a user can view the report. - 'block/xp:viewreport' => array( + 'block/xp:viewreport' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'block/xp:manage' - ) -); + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'block/xp:manage', + ], +]; diff --git a/db/caches.php b/db/caches.php index 0f489832..9de512ea 100644 --- a/db/caches.php +++ b/db/caches.php @@ -24,15 +24,15 @@ defined('MOODLE_INTERNAL') || die(); -$definitions = array( - 'filters' => array( +$definitions = [ + 'filters' => [ 'mode' => cache_store::MODE_APPLICATION, 'simplekeys' => true, - 'staticacceleration' => true - ), + 'staticacceleration' => true, + ], - 'ruleevent_eventslist' => array( + 'ruleevent_eventslist' => [ 'mode' => cache_store::MODE_APPLICATION, - 'simplekeys' => true - ) -); + 'simplekeys' => true, + ], +]; diff --git a/db/services.php b/db/services.php index 97ee90bb..4c0501a5 100644 --- a/db/services.php +++ b/db/services.php @@ -31,21 +31,21 @@ 'methodname' => 'execute', 'description' => 'Mark popup notification as seen', 'type' => 'write', - 'ajax' => true + 'ajax' => true, ], 'block_xp_search_courses' => [ 'classname' => 'block_xp\external\search_courses', 'methodname' => 'execute', 'description' => 'Search for courses', 'type' => 'read', - 'ajax' => true + 'ajax' => true, ], 'block_xp_search_modules' => [ 'classname' => 'block_xp\external\search_modules', 'methodname' => 'execute', 'description' => 'Search modules within a course', 'type' => 'read', - 'ajax' => true + 'ajax' => true, ], 'block_xp_set_default_levels_info' => [ 'classname' => 'block_xp\external\set_default_levels_info', diff --git a/db/upgrade.php b/db/upgrade.php index 93bf2fed..12f54b49 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -97,7 +97,7 @@ function xmldb_block_xp_upgrade($oldversion) { // Define index courseid (unique) to be added to block_xp_config. $table = new xmldb_table('block_xp_config'); - $index = new xmldb_index('courseid', XMLDB_INDEX_UNIQUE, array('courseid')); + $index = new xmldb_index('courseid', XMLDB_INDEX_UNIQUE, ['courseid']); // Conditionally launch add index courseid. if (!$dbman->index_exists($table, $index)) { @@ -136,10 +136,10 @@ function xmldb_block_xp_upgrade($oldversion) { $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); // Adding keys to table block_xp_filters. - $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); // Adding indexes to table block_xp_filters. - $table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, array('courseid')); + $table->add_index('courseid', XMLDB_INDEX_NOTUNIQUE, ['courseid']); // Conditionally launch create table for block_xp_filters. if (!$dbman->table_exists($table)) { @@ -213,7 +213,7 @@ function xmldb_block_xp_upgrade($oldversion) { if ($oldversion < 2016021500) { // We changed the way the "Level up" notifications are triggered, so we'll remove the old flags from the database. - $DB->delete_records('user_preferences', array('name' => 'block_xp_notify_level_up')); + $DB->delete_records('user_preferences', ['name' => 'block_xp_notify_level_up']); // Xp savepoint reached. upgrade_block_savepoint(true, 2016021500, 'xp'); diff --git a/lib.php b/lib.php index 9b71cb76..e160c067 100644 --- a/lib.php +++ b/lib.php @@ -36,7 +36,7 @@ * @param array $options Array of options. * @return void|false */ -function block_xp_pluginfile($course, $bi, $context, $filearea, $args, $forcedownload, array $options = array()) { +function block_xp_pluginfile($course, $bi, $context, $filearea, $args, $forcedownload, array $options = []) { $fs = di::get('file_server'); if ($fs instanceof \block_xp\local\file\block_file_server) { $fs->serve_block_file($course, $bi, $context, $filearea, $args, $forcedownload, $options); @@ -98,6 +98,6 @@ function block_xp_user_preferences() { global $USER; return $user->id == $USER->id; }, - ] + ], ]; } diff --git a/renderer.php b/renderer.php index f3301110..948773b9 100644 --- a/renderer.php +++ b/renderer.php @@ -287,22 +287,22 @@ public function notices(\block_xp\local\course_world $world) { function() { $questblogurl = new moodle_url('https://www.levelup.plus/blog/quest-moodle-gamification-plugin?ref=xp_notice'); $questurl = new moodle_url('https://www.levelup.plus/quest?ref=xp_notice'); - return strip_tags(markdown_to_html(get_string('questreleasenotice', 'block_xp', (object) array( + return strip_tags(markdown_to_html(get_string('questreleasenotice', 'block_xp', (object) [ 'questblogurl' => $questblogurl->out(false), - 'questurl' => $questurl->out(false) - ))), ''); - } + 'questurl' => $questurl->out(false), + ])), ''); + }, ], [ $this->noticesflag, function() { $moodleorgurl = new moodle_url('https://moodle.org/plugins/view.php?plugin=block_xp'); $githuburl = new moodle_url('https://github.com/FMCorz/moodle-block_xp'); - return get_string('likenotice', 'block_xp', (object) array( + return get_string('likenotice', 'block_xp', (object) [ 'moodleorg' => $moodleorgurl->out(), - 'github' => $githuburl->out() - )); - } - ] + 'github' => $githuburl->out(), + ]); + }, + ], ]; foreach ($candidates as $candidate) { if (!get_user_preferences($candidate[0], false)) { @@ -347,7 +347,7 @@ function() { } $icon = new pix_icon('t/close', get_string('dismissnotice', 'block_xp'), 'block_xp'); - $actionicon = $this->action_icon(new moodle_url($this->page->url), $icon, null, array('class' => 'block-xp-rocks')); + $actionicon = $this->action_icon(new moodle_url($this->page->url), $icon, null, ['class' => 'block-xp-rocks']); $text = html_writer::start_div('xp-flex xp-gap-1'); $text .= html_writer::div($textfn(), 'xp-flex-1 [&_a]:xp-font-normal [&_a]:xp-underline'); @@ -576,7 +576,7 @@ public function pix_url($image, $component = 'moodle') { * @param array $options Options. * @return string */ - public function render(renderable $renderable, $options = array()) { + public function render(renderable $renderable, $options = []) { if ($renderable instanceof block_xp_ruleset) { return $this->render_block_xp_ruleset($renderable, $options); } else if ($renderable instanceof block_xp_rule) { @@ -599,7 +599,7 @@ public function render_block_xp_filter($filter) { $o = ''; $basename = 'filters[' . $i++ . ']'; - $o .= html_writer::start_tag('li', array('class' => 'filter', 'data-basename' => $basename)); + $o .= html_writer::start_tag('li', ['class' => 'filter', 'data-basename' => $basename]); if ($filter->is_editable()) { $content = ''; @@ -607,18 +607,18 @@ public function render_block_xp_filter($filter) { $content .= html_writer::start_div('xp-flex-none xp-h-10 xp-flex xp-items-center'); $content .= $this->render(new pix_icon('i/dragdrop', get_string('moverule', 'block_xp'), '', - array('class' => 'iconsmall filter-move'))); + ['class' => 'iconsmall filter-move'])); $content .= html_writer::end_div(); $content .= html_writer::start_div('xp-flex-1 xp-overflow-hidden xp-min-h-full xp-flex' . ' xp-items-center xp-leading-tight'); $content .= get_string('awardaxpwhen', 'block_xp', - html_writer::empty_tag('input', array( + html_writer::empty_tag('input', [ 'type' => 'text', 'value' => $filter->get_points(), 'size' => 3, 'name' => $basename . '[points]', - 'class' => 'form-control block_xp-form-control-inline !xp-mr-1')) + 'class' => 'form-control block_xp-form-control-inline !xp-mr-1', ]) ); $content .= html_writer::end_div(); @@ -629,21 +629,21 @@ public function render_block_xp_filter($filter) { $content .= html_writer::end_div(); $o .= html_writer::div($content, 'xp-group'); - $o .= html_writer::empty_tag('input', array( + $o .= html_writer::empty_tag('input', [ 'type' => 'hidden', 'value' => $filter->get_id(), - 'name' => $basename . '[id]')); - $o .= html_writer::empty_tag('input', array( + 'name' => $basename . '[id]', ]); + $o .= html_writer::empty_tag('input', [ 'type' => 'hidden', 'value' => $filter->get_sortorder(), - 'name' => $basename . '[sortorder]')); + 'name' => $basename . '[sortorder]', ]); $basename .= '[rule]'; } else { $o .= html_writer::tag('p', get_string('awardaxpwhen', 'block_xp', $filter->get_points())); } - $o .= html_writer::start_tag('ul', array('class' => 'filter-rules')); - $o .= $this->render($filter->get_rule(), array('iseditable' => $filter->is_editable(), 'basename' => $basename)); + $o .= html_writer::start_tag('ul', ['class' => 'filter-rules']); + $o .= $this->render($filter->get_rule(), ['iseditable' => $filter->is_editable(), 'basename' => $basename]); $o .= html_writer::end_tag('ul'); $o .= html_writer::end_tag('li'); return $o; @@ -683,8 +683,8 @@ public function render_block_xp_rule($rule, $options) { $content = s($rule->get_description()); } $o = ''; - $o .= html_writer::start_tag('li', array('class' => 'rule rule-type-rule xp-group')); - $o .= html_writer::tag('div', $content, array('class' => 'rule-definition', 'data-basename' => $basename)); + $o .= html_writer::start_tag('li', ['class' => 'rule rule-type-rule xp-group']); + $o .= html_writer::tag('div', $content, ['class' => 'rule-definition', 'data-basename' => $basename]); $o .= html_writer::end_tag('li'); return $o; } @@ -701,14 +701,14 @@ public function render_block_xp_ruleset($ruleset, $options) { $iseditable = !empty($options['iseditable']); $basename = isset($options['basename']) ? $options['basename'] : ''; $o = ''; - $o .= html_writer::start_tag('li', array('class' => 'rule rule-type-ruleset')); + $o .= html_writer::start_tag('li', ['class' => 'rule rule-type-ruleset']); if ($iseditable) { $content = ''; $content .= html_writer::start_div('xp-flex xp-min-h-10'); $content .= html_writer::start_div('xp-flex-none xp-h-10 xp-flex xp-items-center'); $content .= $this->render(new pix_icon('i/dragdrop', get_string('movecondition', 'block_xp'), '', - array('class' => 'iconsmall rule-move'))); + ['class' => 'iconsmall rule-move'])); $content .= html_writer::end_div(); $content .= html_writer::start_div('xp-flex-1 xp-overflow-hidden xp-min-h-full xp-flex' @@ -724,8 +724,8 @@ public function render_block_xp_ruleset($ruleset, $options) { } else { $content = s($ruleset->get_description()); } - $o .= html_writer::tag('div', $content, array('class' => 'rule-definition xp-h-10 xp-group', 'data-basename' => $basename)); - $o .= html_writer::start_tag('ul', array('class' => 'rule-rules', 'data-basename' => $basename . '[rules]')); + $o .= html_writer::tag('div', $content, ['class' => 'rule-definition xp-h-10 xp-group', 'data-basename' => $basename]); + $o .= html_writer::start_tag('ul', ['class' => 'rule-rules', 'data-basename' => $basename . '[rules]']); foreach ($ruleset->get_rules() as $rule) { if ($iseditable) { $options['basename'] = $basename . '[rules][' . $i++ . ']'; @@ -733,9 +733,9 @@ public function render_block_xp_ruleset($ruleset, $options) { $o .= $this->render($rule, $options); } if ($iseditable) { - $o .= html_writer::start_tag('li', array('class' => 'rule-add')); + $o .= html_writer::start_tag('li', ['class' => 'rule-add']); $o .= $this->action_link('#', get_string('addacondition', 'block_xp'), null, null, - new pix_icon('t/add', '', '', array('class' => 'iconsmall'))); + new pix_icon('t/add', '', '', ['class' => 'iconsmall'])); $o .= html_writer::end_tag('li'); } $o .= html_writer::end_tag('ul'); @@ -755,7 +755,7 @@ public function render_block_xp_rule_delete_action_link($str, $classname = '') { return $this->action_link('#', '', null, [ 'class' => $classname . ' supports-hover:xp-opacity-0 supports-hover:xp-pointer-events-none' . ' focus:xp-opacity-100 focus:xp-pointer-events-auto' - . ' group-hover:xp-opacity-100 group-hover:xp-pointer-events-auto xp-transition-opacity' + . ' group-hover:xp-opacity-100 group-hover:xp-pointer-events-auto xp-transition-opacity', ], $icon); } @@ -818,7 +818,7 @@ public function render_filters_widget(renderable $widget) { $templatetypes[] = [ 'name' => $rule->name, 'info' => !empty($rule->info) ? $rule->info : null, - 'template' => $this->render($rule->rule, ['iseditable' => true, 'basename' => 'XXXXX']) + 'template' => $this->render($rule->rule, ['iseditable' => true, 'basename' => 'XXXXX']), ]; } @@ -826,8 +826,8 @@ public function render_filters_widget(renderable $widget) { $this->page->requires->yui_module('moodle-block_xp-filters', 'Y.M.block_xp.Filters.init', [[ 'containerSelector' => '#' . $containerid, 'filter' => $templatefilter, - 'rules' => $templatetypes - ]]); + 'rules' => $templatetypes, + ], ]); $this->page->requires->strings_for_js(['pickaconditiontype', 'deleterule', 'deletecondition'], 'block_xp'); $this->page->requires->strings_for_js(['areyousure'], 'core'); } @@ -904,10 +904,10 @@ public function render_filters_widget_group(renderable $group) { echo html_writer::start_tag('p', ['class' => 'block-xp-filters-submit-actions']); echo html_writer::empty_tag('input', ['value' => get_string('savechanges'), 'type' => 'submit', 'name' => 'save', - 'class' => 'btn btn-primary']); + 'class' => 'btn btn-primary', ]); echo ' '; echo html_writer::empty_tag('input', ['value' => get_string('cancel'), 'type' => 'submit', 'name' => 'cancel', - 'class' => 'btn btn-default btn-secondary']); + 'class' => 'btn btn-default btn-secondary', ]); echo html_writer::end_tag('p'); echo html_writer::end_tag('form'); @@ -954,7 +954,7 @@ protected function get_progress_bar_context(state $state, $percentagetogo = fals 'nonzero' => $pc != 0, 'percentage' => $pc, 'percentagehuman' => $pc > 0 ? floor($pc) : ceil($pc), - 'nextinvaluehtml' => $nextinvalue + 'nextinvaluehtml' => $nextinvalue, ]; } @@ -1021,7 +1021,7 @@ public function recent_activity(array $activity, moodle_url $moreurl = null) { 'date' => userdate($entry->get_date()->getTimestamp()), 'dateagotiny' => $this->tiny_time_ago($entry->get_date()), 'description' => $entry->get_description(), - 'xphtml' => $xp !== null ? $this->xp($xp) : '' + 'xphtml' => $xp !== null ? $this->xp($xp) : '', ]; }, $activity)), ]); @@ -1071,9 +1071,9 @@ public function sub_navigation($items, $activenode) { } return array_merge($item, [ 'url' => $url, - 'current' => $item['id'] == $activenode + 'current' => $item['id'] == $activenode, ]); - }, $items) + }, $items), ]); } @@ -1163,7 +1163,7 @@ public function user_avatar(moodle_url $url = null, moodle_url $link = null) { if ($link) { return html_writer::link($link->out(false), $img, [ - 'class' => 'd-inline-block aabtn' + 'class' => 'd-inline-block aabtn', ]); } @@ -1197,7 +1197,7 @@ public function xp_highlight($amount, $bright = true) { return html_writer::tag( 'span', html_writer::tag('span', $this->xp($amount), [ - 'class' => "xp-inline-block $colourclass xp-px-2 xp-py-0.5 xp-rounded-xl xp-leading-none" + 'class' => "xp-inline-block $colourclass xp-px-2 xp-py-0.5 xp-rounded-xl xp-leading-none", ]), ['class' => 'block_xp block_xp-xp-highlight'] ); diff --git a/tests/algo_levels_info_test.php b/tests/algo_levels_info_test.php index 7d03d164..bced58e0 100644 --- a/tests/algo_levels_info_test.php +++ b/tests/algo_levels_info_test.php @@ -202,18 +202,18 @@ public function test_data_parsing() { "1" => 'A', "2" => 'Level Too!', "3" => 'aaaa', - "6" => 'X' + "6" => 'X', ], 'desc' => [ '1' => 'a', '2' => 'bB', '3' => '3', '5' => 'five', - '6' => 'xx' + '6' => 'xx', ], 'base' => 120, 'coef' => 1.2, - 'usealgo' => false + 'usealgo' => false, ]; $levelsinfo = new algo_levels_info($sampledata); @@ -226,7 +226,7 @@ public function test_data_parsing() { 3 => 264, 4 => 437, 5 => 644, - 6 => 893 + 6 => 893, ], $this->get_xp_by_levels($levelsinfo)); $this->assertEquals([ 1 => 'A', @@ -234,7 +234,7 @@ public function test_data_parsing() { 3 => 'aaaa', 4 => '', 5 => '', - 6 => 'X' + 6 => 'X', ], $this->get_name_by_levels($levelsinfo)); $this->assertEquals([ 1 => 'a', @@ -242,7 +242,7 @@ public function test_data_parsing() { 3 => '3', 4 => '', 5 => 'five', - 6 => 'xx' + 6 => 'xx', ], $this->get_description_by_levels($levelsinfo)); $sampledata = [ @@ -256,13 +256,13 @@ public function test_data_parsing() { '7' => 1531, '8' => 2110, '9' => 2863, - '10' => 3842 + '10' => 3842, ], 'name' => [], 'desc' => [], 'base' => 120, 'coef' => 1.3, - 'usealgo' => true + 'usealgo' => true, ]; $levelsinfo = new algo_levels_info($sampledata); @@ -321,7 +321,7 @@ public function test_data_parsing_with_inconsistencies() { ], 'desc' => [ '5' => 'Desc 5', - '6' => 'Desc 6' // Key does not match level. + '6' => 'Desc 6', // Key does not match level. ], // Missing algo. ]; @@ -338,7 +338,7 @@ public function test_data_parsing_with_inconsistencies() { 3 => 264, 4 => 437, 5 => 644, - 6 => 893 + 6 => 893, ], $this->get_xp_by_levels($levelsinfo)); $this->assertEquals([ 1 => '', @@ -346,7 +346,7 @@ public function test_data_parsing_with_inconsistencies() { 3 => '', 4 => '', 5 => '', - 6 => '' + 6 => '', ], $this->get_name_by_levels($levelsinfo)); $this->assertEquals([ 1 => '', @@ -354,7 +354,7 @@ public function test_data_parsing_with_inconsistencies() { 3 => '', 4 => '', 5 => 'Desc 5', - 6 => '' + 6 => '', ], $this->get_description_by_levels($levelsinfo)); $sampledata = [ @@ -366,7 +366,7 @@ public function test_data_parsing_with_inconsistencies() { ], 'desc' => [ '5' => 'Desc 5', - '6' => 'Desc 6' // Key does not match level. + '6' => 'Desc 6', // Key does not match level. ], // Missing algo. ]; @@ -383,7 +383,7 @@ public function test_data_parsing_with_inconsistencies() { 3 => 264, 4 => 437, 5 => 644, - 6 => 893 + 6 => 893, ], $this->get_xp_by_levels($levelsinfo)); $this->assertEquals([ 1 => '', @@ -391,7 +391,7 @@ public function test_data_parsing_with_inconsistencies() { 3 => '', 4 => '', 5 => '', - 6 => '' + 6 => '', ], $this->get_name_by_levels($levelsinfo)); $this->assertEquals([ 1 => '', @@ -399,7 +399,7 @@ public function test_data_parsing_with_inconsistencies() { 3 => '', 4 => '', 5 => 'Desc 5', - 6 => '' + 6 => '', ], $this->get_description_by_levels($levelsinfo)); } diff --git a/tests/backup_test.php b/tests/backup_test.php index 8f0048e8..09496e92 100644 --- a/tests/backup_test.php +++ b/tests/backup_test.php @@ -304,10 +304,10 @@ public function test_restore_grade_filter_with_none_existing() { $rule = new block_xp_ruleset([new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname')]); block_xp_filter::load_from_data(['rule' => $rule, 'points' => 1, 'courseid' => $c1->id, 'sortorder' => 0, - 'category' => block_xp_filter::CATEGORY_GRADES])->save(); + 'category' => block_xp_filter::CATEGORY_GRADES, ])->save(); $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); $this->setAdminUser(); $backupid = $this->backup($c1); @@ -317,7 +317,7 @@ public function test_restore_grade_filter_with_none_existing() { // The filter has been restored. $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $newid, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); } /** @@ -336,11 +336,11 @@ public function test_restore_grade_filter_with_one_existing() { $rule = new block_xp_ruleset([new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname')]); $filter = block_xp_filter::load_from_data(['rule' => $rule, 'points' => 1, 'courseid' => $c1->id, 'sortorder' => 0, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $filter->save(); $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); $this->setAdminUser(); $backupid = $this->backup($c1); @@ -350,7 +350,7 @@ public function test_restore_grade_filter_with_one_existing() { // Another filter has not been created. $this->assertTrue($DB->record_exists('block_xp_filters', ['id' => $filter->get_id()])); $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); } /** @@ -369,11 +369,11 @@ public function test_restore_grade_filter_with_one_non_ruleset_existing() { $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname'); $filter = block_xp_filter::load_from_data(['rule' => $rule, 'points' => 1, 'courseid' => $c1->id, 'sortorder' => 0, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $filter->save(); $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); $this->setAdminUser(); $backupid = $this->backup($c1); @@ -383,7 +383,7 @@ public function test_restore_grade_filter_with_one_non_ruleset_existing() { // Another filter has not been created. $this->assertTrue($DB->record_exists('block_xp_filters', ['id' => $filter->get_id()])); $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); } /** @@ -402,15 +402,15 @@ public function test_restore_grade_filter_with_many_existing() { $rule = new block_xp_ruleset([new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname')]); $filter1 = block_xp_filter::load_from_data(['rule' => $rule, 'points' => 1, 'courseid' => $c1->id, 'sortorder' => 0, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $filter1->save(); $rule = new block_xp_ruleset([new block_xp_rule_property(block_xp_rule_base::CT, 'somethingelse', 'eventname')]); $filter2 = block_xp_filter::load_from_data(['rule' => $rule, 'points' => 2, 'courseid' => $c1->id, 'sortorder' => 0, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $filter2->save(); $this->assertEquals(2, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); $this->setAdminUser(); $backupid = $this->backup($c1); @@ -421,7 +421,7 @@ public function test_restore_grade_filter_with_many_existing() { $this->assertTrue($DB->record_exists('block_xp_filters', ['id' => $filter1->get_id()])); $this->assertTrue($DB->record_exists('block_xp_filters', ['id' => $filter2->get_id()])); $this->assertEquals(2, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); } /** @@ -440,7 +440,7 @@ public function test_restore_grade_filter_with_one_empty_existing() { $rule = new block_xp_ruleset([new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname')]); $filter = block_xp_filter::load_from_data(['rule' => $rule, 'points' => 1, 'courseid' => $c1->id, 'sortorder' => 0, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $filter->save(); $origfilterid = $filter->get_id(); $this->assertNotEmpty($filter->get_rule()->get_rules()); @@ -455,7 +455,7 @@ public function test_restore_grade_filter_with_one_empty_existing() { $filter->save(); $record = $DB->get_record('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $dbfilter = block_xp_filter::load_from_data($record); $this->assertEquals($filter->get_id(), $dbfilter->get_id()); $this->assertEmpty($filter->get_rule()->get_rules()); @@ -466,9 +466,9 @@ public function test_restore_grade_filter_with_one_empty_existing() { // The filter has been replaced. $this->assertEquals(1, $DB->count_records('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES])); + 'category' => block_xp_filter::CATEGORY_GRADES, ])); $record = $DB->get_record('block_xp_filters', ['courseid' => $c1->id, - 'category' => block_xp_filter::CATEGORY_GRADES]); + 'category' => block_xp_filter::CATEGORY_GRADES, ]); $filter = block_xp_filter::load_from_data($record); $this->assertEquals($origfilterid, $filter->get_id()); $this->assertNotEmpty($filter->get_rule()->get_rules()); diff --git a/tests/course_world_collection_strategy_test.php b/tests/course_world_collection_strategy_test.php index 94adf91e..9f813cfa 100644 --- a/tests/course_world_collection_strategy_test.php +++ b/tests/course_world_collection_strategy_test.php @@ -53,7 +53,7 @@ public function test_is_action_accepted_not_in_log() { $now = time(); $log = [ 'a' => [$now - 1000, $now - 2000, $now - 100, $now], - 'b' => [$now - 1000, $now - 2000, $now - 100, $now] + 'b' => [$now - 1000, $now - 2000, $now - 100, $now], ]; $this->assertFalse(course_world_collection_strategy::is_action_accepted('c', $now, $log, 4, 1000, 0)); $this->assertTrue(course_world_collection_strategy::is_action_accepted('c', $now, $log, 5, 1000, 0)); diff --git a/tests/course_world_test.php b/tests/course_world_test.php index 7a031a7d..31a76b86 100644 --- a/tests/course_world_test.php +++ b/tests/course_world_test.php @@ -60,11 +60,11 @@ public function test_reset_data() { $world->get_config()->set_many(['enabled' => true, 'timebetweensameactions' => 0]); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $strategy->collect_event($e); @@ -72,21 +72,21 @@ public function test_reset_data() { $world->get_config()->set_many(['enabled' => true, 'timebetweensameactions' => 0]); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $this->assertEquals(2, $DB->count_records('block_xp', array('courseid' => $c1->id))); - $this->assertEquals(4, $DB->count_records('block_xp_log', array('courseid' => $c1->id))); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c2->id))); - $this->assertEquals(1, $DB->count_records('block_xp_log', array('courseid' => $c2->id))); + $this->assertEquals(2, $DB->count_records('block_xp', ['courseid' => $c1->id])); + $this->assertEquals(4, $DB->count_records('block_xp_log', ['courseid' => $c1->id])); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c2->id])); + $this->assertEquals(1, $DB->count_records('block_xp_log', ['courseid' => $c2->id])); $world = $this->get_world($c1->id); $world->get_store()->reset(); - $this->assertEquals(0, $DB->count_records('block_xp', array('courseid' => $c1->id))); - $this->assertEquals(0, $DB->count_records('block_xp_log', array('courseid' => $c1->id))); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c2->id))); - $this->assertEquals(1, $DB->count_records('block_xp_log', array('courseid' => $c2->id))); + $this->assertEquals(0, $DB->count_records('block_xp', ['courseid' => $c1->id])); + $this->assertEquals(0, $DB->count_records('block_xp_log', ['courseid' => $c1->id])); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c2->id])); + $this->assertEquals(1, $DB->count_records('block_xp_log', ['courseid' => $c2->id])); } public function test_reset_data_with_groups() { @@ -96,22 +96,22 @@ public function test_reset_data_with_groups() { $c2 = $this->getDataGenerator()->create_course(); $u1 = $this->getDataGenerator()->create_user(); $u2 = $this->getDataGenerator()->create_user(); - $g1 = $this->getDataGenerator()->create_group(array('courseid' => $c1->id)); + $g1 = $this->getDataGenerator()->create_group(['courseid' => $c1->id]); $this->getDataGenerator()->enrol_user($u1->id, $c1->id); $this->getDataGenerator()->enrol_user($u2->id, $c1->id); $this->getDataGenerator()->enrol_user($u1->id, $c2->id); - $this->getDataGenerator()->create_group_member(array('groupid' => $g1->id, 'userid' => $u1->id)); + $this->getDataGenerator()->create_group_member(['groupid' => $g1->id, 'userid' => $u1->id]); $world = $this->get_world($c1->id); $world->get_config()->set_many(['enabled' => true, 'timebetweensameactions' => 0]); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $strategy->collect_event($e); @@ -119,25 +119,25 @@ public function test_reset_data_with_groups() { $world->get_config()->set_many(['enabled' => true, 'timebetweensameactions' => 0]); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c1->id, 'userid' => $u1->id))); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c1->id, 'userid' => $u2->id))); - $this->assertEquals(2, $DB->count_records('block_xp_log', array('courseid' => $c1->id, 'userid' => $u1->id))); - $this->assertEquals(2, $DB->count_records('block_xp_log', array('courseid' => $c1->id, 'userid' => $u2->id))); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c2->id))); - $this->assertEquals(1, $DB->count_records('block_xp_log', array('courseid' => $c2->id))); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c1->id, 'userid' => $u1->id])); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c1->id, 'userid' => $u2->id])); + $this->assertEquals(2, $DB->count_records('block_xp_log', ['courseid' => $c1->id, 'userid' => $u1->id])); + $this->assertEquals(2, $DB->count_records('block_xp_log', ['courseid' => $c1->id, 'userid' => $u2->id])); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c2->id])); + $this->assertEquals(1, $DB->count_records('block_xp_log', ['courseid' => $c2->id])); $world = $this->get_world($c1->id); $world->get_store()->reset_by_group($g1->id); - $this->assertEquals(0, $DB->count_records('block_xp', array('courseid' => $c1->id, 'userid' => $u1->id))); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c1->id, 'userid' => $u2->id))); - $this->assertEquals(0, $DB->count_records('block_xp_log', array('courseid' => $c1->id, 'userid' => $u1->id))); - $this->assertEquals(2, $DB->count_records('block_xp_log', array('courseid' => $c1->id, 'userid' => $u2->id))); - $this->assertEquals(1, $DB->count_records('block_xp', array('courseid' => $c2->id))); - $this->assertEquals(1, $DB->count_records('block_xp_log', array('courseid' => $c2->id))); + $this->assertEquals(0, $DB->count_records('block_xp', ['courseid' => $c1->id, 'userid' => $u1->id])); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c1->id, 'userid' => $u2->id])); + $this->assertEquals(0, $DB->count_records('block_xp_log', ['courseid' => $c1->id, 'userid' => $u1->id])); + $this->assertEquals(2, $DB->count_records('block_xp_log', ['courseid' => $c1->id, 'userid' => $u2->id])); + $this->assertEquals(1, $DB->count_records('block_xp', ['courseid' => $c2->id])); + $this->assertEquals(1, $DB->count_records('block_xp_log', ['courseid' => $c2->id])); } public function test_delete_user_state() { @@ -201,9 +201,9 @@ public function test_levels_info_loading() { new static_config([ 'levelsdata' => '{"xp":{"1":0,"2":120,"3":264,"4":437,"5":644,"6":893},"name":{"1":"A","2":"Level Too!",' . '"3":"aaaa","6":"X"},"desc":{"1":"a","2":"bB","3":"3","5":"five","6":"xx"},"base":120,"coef":1.2,' - . '"usealgo":false}' + . '"usealgo":false}', ]), - new default_course_world_config() + new default_course_world_config(), ]); $world = new course_world($config, $DB, 1, di::get('badge_url_resolver_course_world_factory')); $levelsinfo = $world->get_levels_info(); @@ -218,7 +218,7 @@ public function test_levels_info_loading() { 3 => 264, 4 => 437, 5 => 644, - 6 => 893 + 6 => 893, ], array_reduce($levelsinfo->get_levels(), function($carry, $level) { $carry[$level->get_level()] = $level->get_xp_required(); return $carry; @@ -230,9 +230,9 @@ public function test_levels_info_loading() { $config = new config_stack([ new static_config([ 'levelsdata' => '{"xp":{"1":0,"2":120,"3":276,"4":479,"5":742,"6":1085,"7":1531,"8":2110,"9":2863,"10":3842},' - . '"name":[],"desc":[],"base":120,"coef":1.3,"usealgo":true}' + . '"name":[],"desc":[],"base":120,"coef":1.3,"usealgo":true}', ]), - new default_course_world_config() + new default_course_world_config(), ]); $world = new course_world($config, $DB, 1, di::get('badge_url_resolver_course_world_factory')); $levelsinfo = $world->get_levels_info(); @@ -267,9 +267,9 @@ public function test_levels_info_loading_with_factory() { new static_config([ 'levelsdata' => '{"xp":{"1":0,"2":120,"3":264,"4":437,"5":644,"6":893},"name":{"1":"A","2":"Level Too!",' . '"3":"aaaa","6":"X"},"desc":{"1":"a","2":"bB","3":"3","5":"five","6":"xx"},"base":120,"coef":1.2,' - . '"usealgo":false}' + . '"usealgo":false}', ]), - new default_course_world_config() + new default_course_world_config(), ]); $world = new course_world($config, $DB, 1, di::get('badge_url_resolver_course_world_factory'), di::get('levels_info_factory')); @@ -285,7 +285,7 @@ public function test_levels_info_loading_with_factory() { 3 => 264, 4 => 437, 5 => 644, - 6 => 893 + 6 => 893, ], array_reduce($levelsinfo->get_levels(), function($carry, $level) { $carry[$level->get_level()] = $level->get_xp_required(); return $carry; @@ -297,9 +297,9 @@ public function test_levels_info_loading_with_factory() { $config = new config_stack([ new static_config([ 'levelsdata' => '{"xp":{"1":0,"2":120,"3":276,"4":479,"5":742,"6":1085,"7":1531,"8":2110,"9":2863,"10":3842},' - . '"name":[],"desc":[],"base":120,"coef":1.3,"usealgo":true}' + . '"name":[],"desc":[],"base":120,"coef":1.3,"usealgo":true}', ]), - new default_course_world_config() + new default_course_world_config(), ]); $world = new course_world($config, $DB, 1, di::get('badge_url_resolver_course_world_factory'), di::get('levels_info_factory')); diff --git a/tests/filters_test.php b/tests/filters_test.php index a7025c32..e3007af2 100644 --- a/tests/filters_test.php +++ b/tests/filters_test.php @@ -53,26 +53,26 @@ protected function get_filter_manager($courseid) { public function test_filter_match() { $rule = new block_xp_rule_property(block_xp_rule_base::EQ, 'c', 'crud'); - $filter = block_xp_filter::load_from_data(array('rule' => $rule)); + $filter = block_xp_filter::load_from_data(['rule' => $rule]); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c')); + $e = \block_xp\event\something_happened::mock(['crud' => 'c']); $this->assertTrue($filter->match($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'd')); + $e = \block_xp\event\something_happened::mock(['crud' => 'd']); $this->assertFalse($filter->match($e)); } public function test_filter_load_rule() { $rulec = new block_xp_rule_property(block_xp_rule_base::EQ, 'c', 'crud'); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c')); + $e = \block_xp\event\something_happened::mock(['crud' => 'c']); - $filter = block_xp_filter::load_from_data(array('rule' => $rulec)); + $filter = block_xp_filter::load_from_data(['rule' => $rulec]); $this->assertTrue($filter->match($e)); - $filter = block_xp_filter::load_from_data(array('ruledata' => json_encode($rulec->export()))); + $filter = block_xp_filter::load_from_data(['ruledata' => json_encode($rulec->export())]); $this->assertTrue($filter->match($e)); - $filter = block_xp_filter::load_from_data(array()); + $filter = block_xp_filter::load_from_data([]); $filter->set_rule($rulec); $this->assertTrue($filter->match($e)); } @@ -83,10 +83,10 @@ public function test_standard_filters() { $course = $this->getDataGenerator()->create_course(); $fm = $this->get_filter_manager($course->id); - $c = \block_xp\event\something_happened::mock(array('crud' => 'c')); - $r = \block_xp\event\something_happened::mock(array('crud' => 'r')); - $u = \block_xp\event\something_happened::mock(array('crud' => 'u')); - $d = \block_xp\event\something_happened::mock(array('crud' => 'd')); + $c = \block_xp\event\something_happened::mock(['crud' => 'c']); + $r = \block_xp\event\something_happened::mock(['crud' => 'r']); + $u = \block_xp\event\something_happened::mock(['crud' => 'u']); + $d = \block_xp\event\something_happened::mock(['crud' => 'd']); $this->assertSame(45, $fm->get_points_for_event($c)); $this->assertSame(9, $fm->get_points_for_event($r)); @@ -102,65 +102,65 @@ public function test_custom_filters() { // Define some custom rules, the sortorder and IDs are mixed here. $rule = new block_xp_rule_property(block_xp_rule_base::EQ, 'c', 'crud'); - $data = array('courseid' => $course->id, 'sortorder' => -20, 'points' => 100, 'rule' => $rule); + $data = ['courseid' => $course->id, 'sortorder' => -20, 'points' => 100, 'rule' => $rule]; block_xp_filter::load_from_data($data)->save(); $fm->invalidate_filters_cache(); - $rule = new block_xp_ruleset(array( + $rule = new block_xp_ruleset([ new block_xp_rule_property(block_xp_rule_base::EQ, 2, 'objectid'), new block_xp_rule_property(block_xp_rule_base::EQ, 'u', 'crud'), - ), block_xp_ruleset::ANY); - $data = array('courseid' => $course->id, 'sortorder' => -10, 'points' => 120, 'rule' => $rule); + ], block_xp_ruleset::ANY); + $data = ['courseid' => $course->id, 'sortorder' => -10, 'points' => 120, 'rule' => $rule]; block_xp_filter::load_from_data($data)->save(); - $rule = new block_xp_ruleset(array( + $rule = new block_xp_ruleset([ new block_xp_rule_property(block_xp_rule_base::GTE, 100, 'objectid'), new block_xp_rule_property(block_xp_rule_base::EQ, 'r', 'crud'), - ), block_xp_ruleset::ALL); - $data = array('courseid' => $course->id, 'sortorder' => -30, 'points' => 130, 'rule' => $rule); + ], block_xp_ruleset::ALL); + $data = ['courseid' => $course->id, 'sortorder' => -30, 'points' => 130, 'rule' => $rule]; block_xp_filter::load_from_data($data)->save(); $fm->invalidate_filters_cache(); // We can override default filters. - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'objectid' => 2)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'objectid' => 2]); $this->assertSame(100, $fm->get_points_for_event($e)); // We can still fallback on default filters. - $e = \block_xp\event\something_happened::mock(array('crud' => 'd')); + $e = \block_xp\event\something_happened::mock(['crud' => 'd']); $this->assertSame(0, $fm->get_points_for_event($e)); // Sort order is respected. - $e = \block_xp\event\something_happened::mock(array('crud' => 'u', 'objectid' => 2)); + $e = \block_xp\event\something_happened::mock(['crud' => 'u', 'objectid' => 2]); $this->assertSame(120, $fm->get_points_for_event($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'r')); + $e = \block_xp\event\something_happened::mock(['crud' => 'r']); $this->assertSame(9, $fm->get_points_for_event($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'r', 'objectid' => 100)); + $e = \block_xp\event\something_happened::mock(['crud' => 'r', 'objectid' => 100]); $this->assertSame(130, $fm->get_points_for_event($e)); // This filter will catch everything before the default rules. $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname'); - $data = array('courseid' => $course->id, 'sortorder' => -5, 'points' => 110, 'rule' => $rule); + $data = ['courseid' => $course->id, 'sortorder' => -5, 'points' => 110, 'rule' => $rule]; block_xp_filter::load_from_data($data)->save(); $fm->invalidate_filters_cache(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'd')); + $e = \block_xp\event\something_happened::mock(['crud' => 'd']); $this->assertSame(110, $fm->get_points_for_event($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'r')); + $e = \block_xp\event\something_happened::mock(['crud' => 'r']); $this->assertSame(110, $fm->get_points_for_event($e)); // This filter will catch everything. $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'something', 'eventname'); - $data = array('courseid' => $course->id, 'sortorder' => -999, 'points' => 1, 'rule' => $rule); + $data = ['courseid' => $course->id, 'sortorder' => -999, 'points' => 1, 'rule' => $rule]; block_xp_filter::load_from_data($data)->save(); $fm->invalidate_filters_cache(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'u', 'objectid' => 2)); + $e = \block_xp\event\something_happened::mock(['crud' => 'u', 'objectid' => 2]); $this->assertSame(1, $fm->get_points_for_event($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'r', 'objectid' => 100)); + $e = \block_xp\event\something_happened::mock(['crud' => 'r', 'objectid' => 100]); $this->assertSame(1, $fm->get_points_for_event($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'd')); + $e = \block_xp\event\something_happened::mock(['crud' => 'd']); $this->assertSame(1, $fm->get_points_for_event($e)); - $e = \block_xp\event\something_happened::mock(array('crud' => 'r')); + $e = \block_xp\event\something_happened::mock(['crud' => 'r']); $this->assertSame(1, $fm->get_points_for_event($e)); } @@ -170,10 +170,10 @@ public function test_validate_data() { // Rule data. $this->assertTrue(block_xp_filter::validate_data([ - 'ruledata' => json_encode(['_class' => 'block_xp_rule_property']) + 'ruledata' => json_encode(['_class' => 'block_xp_rule_property']), ])); $this->assertFalse(block_xp_filter::validate_data([ - 'ruledata' => json_encode(['_class' => 'core_user']) + 'ruledata' => json_encode(['_class' => 'core_user']), ])); // IDs where loose empty values are OK. @@ -209,7 +209,7 @@ public function test_validate_data() { public function test_load_from_data() { $filter = block_xp_filter::load_from_data((object) [ - 'ruledata' => json_encode(['_class' => 'block_xp_rule_property']) + 'ruledata' => json_encode(['_class' => 'block_xp_rule_property']), ]); $this->assertInstanceOf('block_xp_rule_property', $filter->get_rule()); diff --git a/tests/fixtures/events.php b/tests/fixtures/events.php index 8ae0edf4..1a282aa3 100644 --- a/tests/fixtures/events.php +++ b/tests/fixtures/events.php @@ -43,7 +43,7 @@ public function init() { * @return self */ public static function mock($properties) { - $event = static::create(array()); + $event = static::create([]); foreach ($properties as $key => $value) { $event->data[$key] = $value; } diff --git a/tests/leaderboard_factory_test.php b/tests/leaderboard_factory_test.php index c408d0a5..e76270b7 100644 --- a/tests/leaderboard_factory_test.php +++ b/tests/leaderboard_factory_test.php @@ -230,8 +230,8 @@ public function test_factory_with_config_without_groups() { // Without a rank. $config = new config_stack([new static_config([ - 'rankmode' => course_world_config::RANK_OFF - ]), $world->get_config()]); + 'rankmode' => course_world_config::RANK_OFF, + ]), $world->get_config(), ]); $lb = $factory->get_course_leaderboard_with_config($world, $config); $this->assert_ranking($lb->get_ranking(new limit(0, 0)), [ [$u8, 0], @@ -247,8 +247,8 @@ public function test_factory_with_config_without_groups() { // With a relative rank for u8. $this->setUser($u8); $config = new config_stack([new static_config([ - 'rankmode' => course_world_config::RANK_REL - ]), $world->get_config()]); + 'rankmode' => course_world_config::RANK_REL, + ]), $world->get_config(), ]); $lb = $factory->get_course_leaderboard_with_config($world, $config); $this->assert_ranking($lb->get_ranking(new limit(0, 0)), [ [$u8, 0], @@ -264,8 +264,8 @@ public function test_factory_with_config_without_groups() { // With a relative rank for u2. $this->setUser($u2); $config = new config_stack([new static_config([ - 'rankmode' => course_world_config::RANK_REL - ]), $world->get_config()]); + 'rankmode' => course_world_config::RANK_REL, + ]), $world->get_config(), ]); $lb = $factory->get_course_leaderboard_with_config($world, $config); $this->assert_ranking($lb->get_ranking(new limit(0, 0)), [ [$u8, 60], @@ -282,8 +282,8 @@ public function test_factory_with_config_without_groups() { $this->setUser($u2); $config = new config_stack([new static_config([ 'neighbours' => 1, - 'rankmode' => course_world_config::RANK_REL - ]), $world->get_config()]); + 'rankmode' => course_world_config::RANK_REL, + ]), $world->get_config(), ]); $lb = $factory->get_course_leaderboard_with_config($world, $config); $this->assert_ranking($lb->get_ranking(new limit(0, 0)), [ [$u3, 10], @@ -306,7 +306,7 @@ public function test_factory_with_config_without_groups() { 'neighbours' => 3, 'rankmode' => course_world_config::RANK_REL, 'identitymode' => course_world_config::IDENTITY_OFF, - ]), $world->get_config()]); + ]), $world->get_config(), ]); $lb = $factory->get_course_leaderboard_with_config($world, $config); $ranking = array_values(iterator_to_array($lb->get_ranking(new limit(0, 0)))); $this->assertEquals(30, $ranking[0]->get_rank()); diff --git a/tests/levels_info_writer_test.php b/tests/levels_info_writer_test.php index e9b54109..347412f9 100644 --- a/tests/levels_info_writer_test.php +++ b/tests/levels_info_writer_test.php @@ -46,23 +46,23 @@ class levels_info_writer_test extends base_testcase { * * @return array */ - public function update_world_after_restore_provider() { + public static function update_world_after_restore_provider(): array { return [ [''], ['{"xp":{"1":0,"2":120,"3":276,"4":479,"5":742,"6":1085,"7":1531,"8":2110,"9":2863,"10":3842},' - . '"name":[],"desc":[],"base":120,"coef":1.3,"usealgo":true}'], + . '"name":[],"desc":[],"base":120,"coef":1.3,"usealgo":true}', ], ['{"xp":{"1":0,"2":120,"3":264,"4":437,"5":644,"6":893,"7":1192,"8":1550,"9":1980,"10":2496},' - . '"name":[],"desc":[],"base":120,"coef":1.2,"usealgo":true}'], + . '"name":[],"desc":[],"base":120,"coef":1.2,"usealgo":true}', ], ['{"xp":{"1":0,"2":200,"3":300,"4":400,"5":743,"6":1000,"7":1532,"8":2112,"9":2866,"10":3846},' . '"name":{"2":"Num\u00e9ro 2","5":"Name 5"},"desc":{"2":"Desc 2","3":"Desc 3"},' - . '"base":120,"coef":1.3,"usealgo":false}'], + . '"base":120,"coef":1.3,"usealgo":false}', ], ['{"xp":{"1":0,"2":100,"3":210,"4":331,"5":464,"6":611,"7":772,"8":949,"9":1144,"10":1358},' . '"name":{"2":"Niveau 2","3":"Niveau 3","9":"Nom 9"},"desc":{"2":"Desc 2","4":"Desc 4","9":"Desc 9"},' - . '"base":100,"coef":1.1000000000000001,"usealgo":true}'], + . '"base":100,"coef":1.1000000000000001,"usealgo":true}', ], ['{"v":2,"xp":[0,120,276,479,742,1085,1531,2110,2863,3842],' - . '"algo":{"base":120,"coef":1.3,"incr":40,"method":"relative"}}'], + . '"algo":{"base":120,"coef":1.3,"incr":40,"method":"relative"}}', ], ['{"v":2,"xp":[0,80,180,300,440,600],"algo":{"base":80,"coef":1.3,"incr":20,"method":"linear"}}'], - ['{"v":2,"xp":[0,77,154,231,308,385,462,539],"algo":{"base":77,"coef":1.3,"incr":20,"method":"flat"}}'] + ['{"v":2,"xp":[0,77,154,231,308,385,462,539],"algo":{"base":77,"coef":1.3,"incr":20,"method":"flat"}}'], ]; } diff --git a/tests/privacy_provider_test.php b/tests/privacy_provider_test.php index adfb6794..8d855c79 100644 --- a/tests/privacy_provider_test.php +++ b/tests/privacy_provider_test.php @@ -123,7 +123,7 @@ public function test_get_contexts_for_userid() { $world = $this->get_world(SITEID); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); // Set back to course mode to get data on both sides. @@ -133,19 +133,19 @@ public function test_get_contexts_for_userid() { $world = $this->get_world($c1->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $world = $this->get_world($c2->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id]); $strategy->collect_event($e); $world = $this->get_world($c3->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c3->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c3->id]); $strategy->collect_event($e); $contextlist = provider::get_contexts_for_userid($u1->id); @@ -180,9 +180,9 @@ public function test_get_users_in_context() { $world = $this->get_world(SITEID); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u3->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u3->id, 'courseid' => $c1->id]); $strategy->collect_event($e); // Set back to course mode to get data on both sides. @@ -192,14 +192,14 @@ public function test_get_users_in_context() { $world = $this->get_world($c1->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $world = $this->get_world($c2->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id]); $strategy->collect_event($e); $userlist = new userlist(context_system::instance(), 'block_xp'); @@ -229,9 +229,9 @@ public function test_delete_data_for_all_users_in_context() { $world = $this->get_world($c1->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id]); $strategy->collect_event($e); set_user_preference('block_xp_notify_level_up_' . $c1->id, 1, $u1->id); set_user_preference('block_xp_notify_level_up_' . $c1->id, 1, $u2->id); @@ -244,9 +244,9 @@ public function test_delete_data_for_all_users_in_context() { $world = $this->get_world($c2->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id]); $strategy->collect_event($e); set_user_preference('block_xp_notify_level_up_' . $c2->id, 1, $u1->id); set_user_preference('block_xp_notify_level_up_' . $c2->id, 1, $u2->id); @@ -284,9 +284,9 @@ public function test_delete_data_for_user() { $world = $this->get_world($c1->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id]); $strategy->collect_event($e); set_user_preference('block_xp_notify_level_up_' . $c1->id, 1, $u1->id); set_user_preference('block_xp_notify_level_up_' . $c1->id, 1, $u2->id); @@ -299,9 +299,9 @@ public function test_delete_data_for_user() { $world = $this->get_world($c2->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id]); $strategy->collect_event($e); set_user_preference('block_xp_notify_level_up_' . $c2->id, 1, $u1->id); set_user_preference('block_xp_notify_level_up_' . $c2->id, 1, $u2->id); @@ -341,11 +341,11 @@ public function test_delete_data_for_users() { $world = $this->get_world($c1->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u3->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u3->id, 'courseid' => $c1->id]); $strategy->collect_event($e); set_user_preference('block_xp_notify_level_up_' . $c1->id, 1, $u1->id); set_user_preference('block_xp_notify_level_up_' . $c1->id, 1, $u2->id); @@ -361,9 +361,9 @@ public function test_delete_data_for_users() { $world = $this->get_world($c2->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id]); $strategy->collect_event($e); set_user_preference('block_xp_notify_level_up_' . $c2->id, 1, $u1->id); set_user_preference('block_xp_notify_level_up_' . $c2->id, 1, $u2->id); @@ -405,19 +405,19 @@ public function test_export_data_for_user() { $world = $this->get_world($c1->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c1->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c1->id]); $strategy->collect_event($e); $this->assertNotEquals(0, $world->get_store()->get_state($u1->id)->get_xp()); @@ -426,9 +426,9 @@ public function test_export_data_for_user() { $world = $this->get_world($c2->id); $strategy = $world->get_collection_strategy(); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u1->id, 'courseid' => $c2->id]); $strategy->collect_event($e); - $e = \block_xp\event\something_happened::mock(array('crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id)); + $e = \block_xp\event\something_happened::mock(['crud' => 'c', 'userid' => $u2->id, 'courseid' => $c2->id]); $strategy->collect_event($e); $this->assertNotEquals(0, $world->get_store()->get_state($u1->id)->get_xp()); diff --git a/tests/rules_test.php b/tests/rules_test.php index f3f37d0d..5c7a7eda 100644 --- a/tests/rules_test.php +++ b/tests/rules_test.php @@ -44,10 +44,10 @@ class rules_test extends \advanced_testcase { * @covers \block_xp_rule_property */ public function test_rule_property() { - $subject = (object) array( + $subject = (object) [ 'int' => 10, - 'str' => 'I am here.' - ); + 'str' => 'I am here.', + ]; $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str'); $this->assertTrue($rule->match($subject)); @@ -106,36 +106,36 @@ public function test_rule_property() { * @covers \block_xp_ruleset */ public function test_ruleset() { - $subject = (object) array( + $subject = (object) [ 'int' => 10, - ); + ]; - $rs = new block_xp_ruleset(array(), block_xp_ruleset::ANY); + $rs = new block_xp_ruleset([], block_xp_ruleset::ANY); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 10, 'int')); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 99, 'int')); $this->assertTrue($rs->match($subject)); - $rs = new block_xp_ruleset(array(), block_xp_ruleset::ANY); + $rs = new block_xp_ruleset([], block_xp_ruleset::ANY); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 0, 'int')); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 99, 'int')); $this->assertFalse($rs->match($subject)); - $rs = new block_xp_ruleset(array(), block_xp_ruleset::ALL); + $rs = new block_xp_ruleset([], block_xp_ruleset::ALL); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 10, 'int')); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 9, 'int')); $this->assertFalse($rs->match($subject)); - $rs = new block_xp_ruleset(array(), block_xp_ruleset::ALL); + $rs = new block_xp_ruleset([], block_xp_ruleset::ALL); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 10, 'int')); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::LTE, 10, 'int')); $this->assertTrue($rs->match($subject)); - $rs = new block_xp_ruleset(array(), block_xp_ruleset::NONE); + $rs = new block_xp_ruleset([], block_xp_ruleset::NONE); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 10, 'int')); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 99, 'int')); $this->assertFalse($rs->match($subject)); - $rs = new block_xp_ruleset(array(), block_xp_ruleset::NONE); + $rs = new block_xp_ruleset([], block_xp_ruleset::NONE); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 0, 'int')); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 99, 'int')); $this->assertTrue($rs->match($subject)); @@ -147,17 +147,17 @@ public function test_ruleset() { * @covers \block_xp_ruleset */ public function test_nested_ruleset() { - $subject = (object) array( + $subject = (object) [ 'int' => 10, - ); + ]; - $rs = new block_xp_ruleset(array(), block_xp_ruleset::ANY); + $rs = new block_xp_ruleset([], block_xp_ruleset::ANY); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 0, 'int')); - $rs->add_rule(new block_xp_ruleset(array( + $rs->add_rule(new block_xp_ruleset([ new block_xp_rule_property(block_xp_rule_base::EQ, 10, 'int'), new block_xp_rule_property(block_xp_rule_base::LTE, 10, 'int'), - new block_xp_rule_property(block_xp_rule_base::GTE, 10, 'int') - ), block_xp_ruleset::ALL)); + new block_xp_rule_property(block_xp_rule_base::GTE, 10, 'int'), + ], block_xp_ruleset::ALL)); $rs->add_rule(new block_xp_rule_property(block_xp_rule_base::EQ, 99, 'int')); $this->assertTrue($rs->match($subject)); @@ -174,7 +174,7 @@ public function test_export_create() { $this->assertEquals($rule, $newrule); $rule = new block_xp_rule_property(block_xp_rule_base::CT, 'I', 'str'); - $rs = new block_xp_ruleset(array($rule), block_xp_ruleset::ALL); + $rs = new block_xp_ruleset([$rule], block_xp_ruleset::ALL); $newrs = block_xp_rule::create($rs->export()); $this->assertEquals($rs, $newrs);