diff --git a/public/lib/external/tests/classes/externallib_testcase.php b/public/lib/external/tests/classes/externallib_testcase.php index 7e66079b99d..e1ee945347e 100644 --- a/public/lib/external/tests/classes/externallib_testcase.php +++ b/public/lib/external/tests/classes/externallib_testcase.php @@ -21,11 +21,13 @@ use core\exception\coding_exception; use core_external\external_settings; use filter_manager; +// phpcs:disable moodle.NamingConventions.ValidFunctionName.LowercaseMethod + /** * Helper base class for external tests. Helpfull to test capabilities. * - * @package core_webservice - * @copyright 2012 Jerome Mouneyrac + * @package core_external + * @copyright Jerome Mouneyrac * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class externallib_testcase extends \advanced_testcase { @@ -38,10 +40,10 @@ abstract class externallib_testcase extends \advanced_testcase { * @param int $roleid * @return int the role id - mainly returned for creation, so calling function can reuse it */ - public static function assignUserCapability($capability, $contextid, $roleid = null) { + public static function assignUserCapability($capability, $contextid, $roleid = null): int { global $USER; - // Create a new student $USER if $USER doesn't exist + // Create a new student $USER if $USER doesn't exist. if (empty($USER->id)) { $user = self::getDataGenerator()->create_user(); self::setUser($user); @@ -69,7 +71,7 @@ abstract class externallib_testcase extends \advanced_testcase { * - move: -1 means up, 0 means the same, 1 means down. * - applytostrings: true to apply the filter to content and headings, false for just content. */ - public static function configure_filters($filters) { + public static function configure_filters($filters): void { global $CFG; $filterstrings = false; @@ -104,24 +106,31 @@ abstract class externallib_testcase extends \advanced_testcase { * @param int $contextid set the context id if you used assignUserCapability. * @param int $roleid set the role id if you used assignUserCapability. * @param int $courseid set the course id if you used getDataGenerator->enrol_users. - * @param string $enrol set the enrol plugin name if you used getDataGenerator->enrol_users with a different plugin than 'manual'. + * @param string $enrol set the enrol plugin name if you used getDataGenerator->enrol_users + * with a different plugin than 'manual'. */ - public static function unassignUserCapability($capability, $contextid = null, $roleid = null, $courseid = null, $enrol = 'manual') { + public static function unassignUserCapability( + $capability, + $contextid = null, + $roleid = null, + $courseid = null, + $enrol = 'manual', + ): void { global $DB; if (!empty($courseid)) { // Retrieve the role id. - $instances = $DB->get_records('enrol', array('courseid'=>$courseid, 'enrol'=>$enrol)); + $instances = $DB->get_records('enrol', ['courseid' => $courseid, 'enrol' => $enrol]); if (count($instances) != 1) { throw new coding_exception('No found enrol instance for courseid: ' . $courseid . ' and enrol: ' . $enrol); } $instance = reset($instances); - if (is_null($roleid) and $instance->roleid) { + if (is_null($roleid) && $instance->roleid) { $roleid = $instance->roleid; } } else { - if (empty($contextid) or empty($roleid)) { + if (empty($contextid) || empty($roleid)) { throw new coding_exception('unassignUserCapaibility requires contextid/roleid or courseid'); } }