Skip to content

Commit

Permalink
MDL-81634 core: Fix all implicitly defined nullables
Browse files Browse the repository at this point in the history
Note: This does not impact third-party libraries.
  • Loading branch information
andrewnicols committed Aug 2, 2024
1 parent 8a6e856 commit 024e36b
Show file tree
Hide file tree
Showing 391 changed files with 782 additions and 782 deletions.
2 changes: 1 addition & 1 deletion admin/classes/local/settings/filesize.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class filesize extends \admin_setting {
* @param int|null $defaultunit GB, MB, etc. (in bytes)
*/
public function __construct(string $name, string $visiblename, string $description,
int $defaultvalue = null, int $defaultunit = null) {
?int $defaultvalue = null, ?int $defaultunit = null) {

$defaultsetting = self::parse_bytes($defaultvalue);

Expand Down
2 changes: 1 addition & 1 deletion admin/presets/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function test_download_unexisting_preset(): void {
* @param string|null $expectedpresetname Expected preset name.
*/
public function test_import_preset(string $filecontents, bool $expectedpreset, bool $expectedsettings = false,
bool $expectedplugins = false, bool $expecteddebugging = false, string $expectedexception = null,
bool $expectedplugins = false, bool $expecteddebugging = false, ?string $expectedexception = null,
string $expectedpresetname = 'Imported preset'): void {
global $DB;

Expand Down
2 changes: 1 addition & 1 deletion admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ public function plugins_check_table(core_plugin_manager $pluginman, $version, ar
* @param null|moodle_url $cancel URL for the cancel link, defaults to the current page
* @return string HTML
*/
public function plugins_management_confirm_buttons(moodle_url $continue=null, moodle_url $cancel=null) {
public function plugins_management_confirm_buttons(?moodle_url $continue=null, ?moodle_url $cancel=null) {

$out = html_writer::start_div('plugins-management-confirm-buttons');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class import_test extends \advanced_testcase {
* @param string|null $expectedpresetname Expected preset name.
*/
public function test_import_execute(string $filecontents, bool $expectedpreset, bool $expectedsettings = false,
bool $expectedplugins = false, bool $expecteddebugging = false, string $expectedexception = null,
bool $expectedplugins = false, bool $expecteddebugging = false, ?string $expectedexception = null,
string $expectedpresetname = 'Imported preset'): void {
global $DB, $USER;

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/brickfield/classes/brickfieldconnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected function get_siteurl(): string {
* @param null|string $secretkey The secret key to use
* @return null|string The registration ID if registration was successful, or null if not
*/
protected function get_registration_id_for_credentials(string $apikey = null, string $secretkey = null): string {
protected function get_registration_id_for_credentials(?string $apikey = null, ?string $secretkey = null): string {
$headers = $this->get_common_headers();
if ($apikey || $secretkey) {
$headers['secret'] = $apikey;
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/brickfield/classes/local/tool/filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function has_course_filters(): bool {
* @throws \coding_exception
* @throws \dml_exception
*/
public function can_access(\context $context = null, string $capability = ''): bool {
public function can_access(?\context $context = null, string $capability = ''): bool {
if ($capability == '') {
if ($this->has_course_filters()) {
$capability = accessibility::get_capability_name('viewcoursetools');
Expand All @@ -176,7 +176,7 @@ public function can_access(\context $context = null, string $capability = ''): b
* @throws \coding_exception
* @throws \dml_exception
*/
public function has_capability_in_context(string $capability, \context $context = null): bool {
public function has_capability_in_context(string $capability, ?\context $context = null): bool {
$coursefiltersvalid = $this->has_course_filters();
if ($context === null) {
// If the filter is using a list of courses ($this->>courseids), use the system context.
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/brickfield/classes/local/tool/tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function get_toolshortname(): string {
* @throws \coding_exception
* @throws \dml_exception
*/
public function can_access(filter $filter, \context $context = null): bool {
public function can_access(filter $filter, ?\context $context = null): bool {
return $filter->can_access($context);
}

Expand Down Expand Up @@ -309,7 +309,7 @@ public static function get_instance_name(string $component, string $table, ?int
* @param filter|null $filter
* @return array
*/
public static function toplevel_arguments(filter $filter = null): array {
public static function toplevel_arguments(?filter $filter = null): array {
if ($filter !== null) {
return ['courseid' => $filter->courseid, 'categoryid' => $filter->categoryid];
} else {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/brickfield/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public static function delete_summary_data(int $courseid) {
* @throws \coding_exception
* @throws \dml_exception
*/
public static function store_result_summary(int $courseid = null) {
public static function store_result_summary(?int $courseid = null) {
global $DB;

if (static::is_okay_to_cache() && ($courseid == null)) {
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/customlang/classes/local/mlang/langstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class langstring {
* @param int $deleted
* @param stdclass $extra
*/
public function __construct(string $id, string $text = '', int $timemodified = null,
int $deleted = 0, stdclass $extra = null) {
public function __construct(string $id, string $text = '', ?int $timemodified = null,
int $deleted = 0, ?stdclass $extra = null) {

if (is_null($timemodified)) {
$timemodified = time();
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/customlang/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function list_components() {
* @param string $lang language code to checkout
* @param progress_bar $progressbar optionally, the given progress bar can be updated
*/
public static function checkout($lang, progress_bar $progressbar = null) {
public static function checkout($lang, ?progress_bar $progressbar = null) {
global $DB, $CFG;

require_once("{$CFG->libdir}/adminlib.php");
Expand Down
10 changes: 5 additions & 5 deletions admin/tool/dataprivacy/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ public static function require_can_create_data_request_for_user($user, $requeste
* @param int|null $userid
* @return bool
*/
public static function can_create_data_download_request_for_self(int $userid = null): bool {
public static function can_create_data_download_request_for_self(?int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:downloadownrequest', \context_user::instance($userid), $userid);
Expand All @@ -834,7 +834,7 @@ public static function can_create_data_download_request_for_self(int $userid = n
* @return bool
* @throws coding_exception
*/
public static function can_create_data_deletion_request_for_self(int $userid = null): bool {
public static function can_create_data_deletion_request_for_self(?int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:requestdelete', \context_user::instance($userid), $userid)
Expand All @@ -849,7 +849,7 @@ public static function can_create_data_deletion_request_for_self(int $userid = n
* @throws coding_exception
* @throws dml_exception
*/
public static function can_create_data_deletion_request_for_other(int $userid = null): bool {
public static function can_create_data_deletion_request_for_other(?int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:requestdeleteforotheruser', context_system::instance(), $userid);
Expand All @@ -863,7 +863,7 @@ public static function can_create_data_deletion_request_for_other(int $userid =
* @return bool
* @throws coding_exception
*/
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
public static function can_create_data_deletion_request_for_children(int $userid, ?int $requesterid = null): bool {
global $USER;
$requesterid = $requesterid ?: $USER->id;
return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
Expand Down Expand Up @@ -1363,7 +1363,7 @@ public static function is_automatic_request_approval_on(int $type): bool {
* @param int $requestid The data request ID.
* @param int $userid Optional. The user ID to run the task as, if necessary.
*/
public static function queue_data_request_task(int $requestid, int $userid = null): void {
public static function queue_data_request_task(int $requestid, ?int $userid = null): void {
$task = new process_data_request_task();
$task->set_custom_data(['requestid' => $requestid]);
if ($userid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class expired_contexts_manager {
*
* @param \progress_trace $trace
*/
public function __construct(\progress_trace $trace = null) {
public function __construct(?\progress_trace $trace = null) {
if (null === $trace) {
$trace = new \null_progress_trace();
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/classes/purpose.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class purpose extends \core\persistent {
* @param int $id If set, this is the id of an existing record, used to load the data.
* @param stdClass $record If set will be passed to {@link self::from_record()}.
*/
public function __construct($id = 0, stdClass $record = null) {
public function __construct($id = 0, ?stdClass $record = null) {
global $CFG;

if ($id) {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2165,7 +2165,7 @@ public function test_set_context_defaults($contextlevel, $inheritcategory, $inhe
* @param string $course Retention policy for courses.
* @param string $activity Retention policy for activities.
*/
protected function setup_basics(string $system, string $user, string $course = null, string $activity = null): \stdClass {
protected function setup_basics(string $system, string $user, ?string $course = null, ?string $activity = null): \stdClass {
$this->resetAfterTest();

$purposes = (object) [
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/dataprivacy/tests/expired_contexts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class expired_contexts_test extends \advanced_testcase {
* @param string $course Retention policy for courses.
* @param string $activity Retention policy for activities.
*/
protected function setup_basics(string $system, string $user, string $course = null, string $activity = null): \stdClass {
protected function setup_basics(string $system, string $user, ?string $course = null, ?string $activity = null): \stdClass {
$this->resetAfterTest();

$purposes = (object) [
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/dbtransfer/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function tool_dbtransfer_export_xml_database($description, $mdb) {
* @param progress_trace $feedback
* @return void
*/
function tool_dbtransfer_transfer_database(moodle_database $sourcedb, moodle_database $targetdb, progress_trace $feedback = null) {
function tool_dbtransfer_transfer_database(moodle_database $sourcedb, moodle_database $targetdb, ?progress_trace $feedback = null) {
core_php_time_limit::raise();

\core\session\manager::write_close(); // Release session.
Expand All @@ -94,7 +94,7 @@ function tool_dbtransfer_transfer_database(moodle_database $sourcedb, moodle_dat
* @return void
* @throws Exception on conversion error
*/
function tool_dbtransfer_rebuild_target_log_actions(moodle_database $target, progress_trace $feedback = null) {
function tool_dbtransfer_rebuild_target_log_actions(moodle_database $target, ?progress_trace $feedback = null) {
global $DB, $CFG;
require_once("$CFG->libdir/upgradelib.php");

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/installaddon/classes/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function instance() {
* @param array optional parameters
* @return moodle_url
*/
public function index_url(array $params = null) {
public function index_url(?array $params = null) {
return new moodle_url('/admin/tool/installaddon/index.php', $params);
}

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/licensemanager/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private function view_license_editor(string $action, string $licenseshortname, e
/**
* View the license manager.
*/
private function view_license_manager(string $message = null): void {
private function view_license_manager(?string $message = null): void {
global $PAGE, $OUTPUT;

$renderer = $PAGE->get_renderer('tool_licensemanager');
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/log/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function delete_data_for_users(\core_privacy\local\request\approve
* @param string $interface The interface to use. By default uses the logstore_provider.
* @return void
*/
protected static function call_subplugins_method_with_args($method, array $args = [], string $interface = null) {
protected static function call_subplugins_method_with_args($method, array $args = [], ?string $interface = null) {
if (!isset($interface)) {
$interface = \tool_log\local\privacy\logstore_provider::class;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/lpmigrate/classes/framework_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class framework_processor {
* @param framework_mapper $mapper The mapper.
* @param \core\progress\base $progress The progress object.
*/
public function __construct(framework_mapper $mapper, \core\progress\base $progress = null) {
public function __construct(framework_mapper $mapper, ?\core\progress\base $progress = null) {
$this->mapper = $mapper;

if ($progress == null) {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/mfa/classes/local/form/verification_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class verification_field extends \MoodleQuickForm_text {
* @param boolean $auth is this constructed in auth.php loginform_* definitions. Set to false to prevent autosubmission of form.
* @param string|null $elementlabel Provide a different element label.
*/
public function __construct($attributes = null, $auth = true, string $elementlabel = null) {
public function __construct($attributes = null, $auth = true, ?string $elementlabel = null) {
global $PAGE;

// Force attributes.
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/mfa/classes/local/secret_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(string $factor) {
* @param string $secret an optional provided secret
* @return string the secret code, or 0 if no new code created.
*/
public function create_secret(int $expires, bool $session, string $secret = null): string {
public function create_secret(int $expires, bool $session, ?string $secret = null): string {
// Check if there already an active secret, unless we are forcibly given a code.
if ($this->has_active_secret($session) && empty($secret)) {
return '';
Expand Down Expand Up @@ -88,7 +88,7 @@ public function create_secret(int $expires, bool $session, string $secret = null
* @param string $sessionid an optional sessionID to tie this record to
* @return void
*/
private function add_secret_to_db(string $secret, int $expires, string $sessionid = null): void {
private function add_secret_to_db(string $secret, int $expires, ?string $sessionid = null): void {
global $DB, $USER;
$expirytime = time() + $expires;

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/mfa/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function setup_factor(object $factor): string {
* @return string $html
* @throws \coding_exception
*/
public function active_factors(string $filterfactor = null): string {
public function active_factors(?string $filterfactor = null): string {
global $USER, $CFG;

require_once($CFG->dirroot . '/iplookup/lib.php');
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/moodlenet/classes/profile_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static function get_user_profile_field(): \stdClass {
* @param int $categoryid The category id to check against.
* @return bool True is the category checks out, otherwise false.
*/
private static function check_profile_category(int $categoryid = null): bool {
private static function check_profile_category(?int $categoryid = null): bool {
global $DB;
$categoryname = self::get_category_name();
$categorydata = $DB->get_record('user_info_category', ['name' => $categoryname]);
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/oauth2/classes/form/issuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class issuer extends persistent {
* @param array $ajaxformdata
*/
public function __construct($action = null, $customdata = null, $method = 'post', $target = '', $attributes = null,
$editable = true, array $ajaxformdata = null) {
$editable = true, ?array $ajaxformdata = null) {
// The type variable defines, if we are in the creation process of a standard issuer.
if (array_key_exists('type', $customdata)) {
$this->type = $customdata['type'];
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/policy/classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public static function can_user_view_policy_version($policy, $behalfid = null, $
* @param array $extrafields Extra fields to be included in result
* @return array of objects
*/
public static function get_user_minors($userid, array $extrafields = null) {
public static function get_user_minors($userid, ?array $extrafields = null) {
global $DB;

$ctxfields = context_helper::get_preload_record_columns_sql('c');
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/uploaduser/classes/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class process {
* @param string|null $progresstrackerclass
* @throws \coding_exception
*/
public function __construct(\csv_import_reader $cir, string $progresstrackerclass = null) {
public function __construct(\csv_import_reader $cir, ?string $progresstrackerclass = null) {
$this->cir = $cir;
if ($progresstrackerclass) {
if (!class_exists($progresstrackerclass) || !is_subclass_of($progresstrackerclass, \uu_progress_tracker::class)) {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/usertours/classes/tour.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ public function set_filter_values($filter, array $values = []) {
* @param array|null $filters Optional array of filters.
* @return bool
*/
public function matches_all_filters(\context $context, array $filters = null): bool {
public function matches_all_filters(\context $context, ?array $filters = null): bool {
if (!$filters) {
$filters = helper::get_all_filters();
}
Expand Down
4 changes: 2 additions & 2 deletions admin/tool/usertours/tests/helper_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait tool_usertours_helper_trait {
* @param bool $persist Whether to persist the data
* @return \tool_usertours\tour
*/
public function helper_create_tour(\stdClass $tourconfig = null, $persist = true) {
public function helper_create_tour(?\stdClass $tourconfig = null, $persist = true) {
$minvalues = [
'id' => null,
'pathmatch' => '/my/%',
Expand Down Expand Up @@ -65,7 +65,7 @@ public function helper_create_tour(\stdClass $tourconfig = null, $persist = true
* @param bool $persist Whether to persist the data
* @return \tool_usertours\step
*/
public function helper_create_step(\stdClass $stepconfig = null, $persist = true) {
public function helper_create_step(?\stdClass $stepconfig = null, $persist = true) {
$minvalues = [
'id' => null,
'title' => '',
Expand Down
2 changes: 1 addition & 1 deletion analytics/classes/local/analyser/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public static function context_restriction_support(): array {
* @param string|null $query Context name filter.
* @return int[]
*/
public static function potential_context_restrictions(string $query = null) {
public static function potential_context_restrictions(?string $query = null) {
return \core_analytics\manager::get_potential_context_restrictions(static::context_restriction_support(), $query);
}

Expand Down
4 changes: 2 additions & 2 deletions analytics/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public static function get_models_with_insights(\context $context) {
* @param int|null $newmodelid A new model to add to the list of models with insights in the provided context.
* @return int[]
*/
public static function cached_models_with_insights(\context $context, int $newmodelid = null) {
public static function cached_models_with_insights(\context $context, ?int $newmodelid = null) {

$cache = \cache::make('core', 'contextwithinsights');
$modelids = $cache->get($context->id);
Expand Down Expand Up @@ -941,7 +941,7 @@ public static function get_declared_target_and_indicators_instances(array $defin
* @param string|null $query
* @return array Associative array with contextid as key and the short version of the context name as value.
*/
public static function get_potential_context_restrictions(?array $contextlevels = null, string $query = null) {
public static function get_potential_context_restrictions(?array $contextlevels = null, ?string $query = null) {
global $DB;

if (empty($contextlevels) && !is_null($contextlevels)) {
Expand Down
Loading

0 comments on commit 024e36b

Please sign in to comment.