Checked phpdoc @return types up to contextinfo.php

This commit is contained in:
PMKuipers 2024-12-27 16:25:21 +01:00
parent 04a1a8b049
commit 136284368c
8 changed files with 98 additions and 79 deletions

View file

@ -80,7 +80,7 @@ abstract class aggregator {
* @param mixed $configstr Configuration string for aggregator
* @throws moodle_exception If method is not found
*/
public static function create($method, $configstr): self {
public static function create($method, $configstr): object {
if (self::supported($method)) {
$agclass = self::aggregator_name($method);
return new $agclass($configstr);
@ -95,7 +95,7 @@ abstract class aggregator {
* @param mixed $method Aggregation method
* @param mixed $configstr Configuration string for aggregator
*/
public static function create_or_default($method, $configstr): self {
public static function create_or_default($method, $configstr): object {
try {
return self::create($method, $configstr);
} catch (\moodle_exception $x) {

View file

@ -106,6 +106,7 @@ class associationservice extends \external_api {
global $DB;
$ctx = \context::instance_by_id($r->contextid);
if (is_object($ctx)) {
$ctxpath = array_reverse($ctx->get_parent_context_ids(true));
if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
array_shift($ctxpath);
@ -121,16 +122,20 @@ class associationservice extends \external_api {
"name" => $ctx->get_context_name(false, false),
"shortname" => $ctx->get_context_name(false, true),
"path" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, false);
$cx = (object)\context::instance_by_id($c);
return $cx->get_context_name(false, false);
}, $ctxpath),
"shortpath" => array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, true);
$cx = (object)\context::instance_by_id($c);
return $cx->get_context_name(false, true);
}, $ctxpath),
],
];
return $result;
} else {
throw new \moodle_exception("");
}
}
/**

View file

@ -397,7 +397,7 @@ class badgeinfo {
* Gets the module instance from the database and returns it.
* If no module instance exists this function returns false.
* @param int $cmid Course module id
* @return stdClass|bool
* @return object|null
*/
private static function get_mod_instance($cmid) {
global $DB;
@ -445,9 +445,10 @@ class badgeinfo {
if ($crit->criteriatype == BADGE_CRITERIA_TYPE_ACTIVITY) {
foreach ($crit->params as $p) {
$mod = self::get_mod_instance($p["module"]);
if (!$mod) {
if (!is_object($mod)) {
$title = get_string('error:nosuchmod', 'badges');
$description = get_string('error:nosuchmod', 'badges');
continue;
} else {
$title = \html_writer::tag('b', '"' . get_string('modulename', $mod->modname) . ' - ' . $mod->name . '"');;
$description = \html_writer::tag('b', '"' . get_string('modulename', $mod->modname) . ' - ' . $mod->name . '"');

View file

@ -103,7 +103,11 @@ class cascadecohortsync {
$groupdata->name = $groupname;
$groupid = groups_create_group($groupdata);
if (is_int($groupid)) {
return $groupid;
} else {
return 0;
}
}
/**

View file

@ -109,7 +109,7 @@ class completionscanner {
'itemmodule' => $this->cm->modname,
'iteminstance' => $this->cm->instance,
'courseid' => $this->courseid]);
if ($gi !== false) {
if (is_object($gi)) {
/* Grade none items should not be relevant.
Note that the grade status is probably only relevant if the item
has not yet received a completion, but has been submitted.

View file

@ -78,11 +78,11 @@ class contextinfo {
public function path($short=false) {
if ($short) {
return array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, true);
return ((object)\context::instance_by_id($c))->get_context_name(false, true);
}, $this->ctxpath);
} else {
return array_map(function($c) {
return \context::instance_by_id($c)->get_context_name(false, false);
return ((object)\context::instance_by_id($c))->get_context_name(false, false);
}, $this->ctxpath);
}
}
@ -113,7 +113,13 @@ class contextinfo {
if ($contextid <= 1) {
$contextid = 1;
}
return \context::instance_by_id($contextid);
$ctx = \context::instance_by_id($contextid);
if (is_object($ctx)) {
return $ctx;
} else {
return \context_system::instance();
}
}
}

View file

@ -50,7 +50,7 @@ class studyplan_editform extends formbase {
* Translate parameters into customdata.
*
* @param object $params The parameters for form initialization
* @return array Form data based on parameters
* @return stdClass Form data based on parameters
*/
public static function init_customdata(object $params) {
$customdata = new stdClass;
@ -87,7 +87,7 @@ class studyplan_editform extends formbase {
* Also validate parameters and access permissions here
*
* @param object $customdata The parameters for form initialization
* @return array Form data based on parameters
* @return object Form data based on parameters
*/
public function init_formdata(object $customdata) {
global $DB;

View file

@ -318,6 +318,7 @@ function local_treestudyplan_send_invite($inviteid) {
$noreply = 'noreply@' . get_host_from_url($CFG->wwwroot);
$mailer = get_mailer();
if ($mailer != null ) {
$mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}");
$mailer->addAddress($invite->email, $invite->name);
$mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}");
@ -367,7 +368,7 @@ function local_treestudyplan_send_invite($inviteid) {
$mailer->AltBody = strip_tags($body);
$mailer->send();
}
}
/**
@ -469,6 +470,7 @@ function local_treestudyplan_pluginfile(
}
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
send_stored_file($file, 24 * 60 * 60, 0, $forcedownload, $options);
return true;
} else {
return false;
}
@ -497,6 +499,7 @@ function local_treestudyplan_pluginfile(
}
// We can now send the file back to the browser - in this case with a cache lifetime of 1 day and no filtering.
send_stored_file($file, 24 * 60 * 60, 0, $forcedownload, $options);
return true;
} else {
return false;
}