From 136284368c492c1325d333ad70832b1c0f93d748 Mon Sep 17 00:00:00 2001
From: PMKuipers
Date: Fri, 27 Dec 2024 16:25:21 +0100
Subject: [PATCH] Checked phpdoc @return types up to contextinfo.php
---
classes/aggregator.php | 4 +-
classes/associationservice.php | 53 +++++++++--------
classes/badgeinfo.php | 5 +-
classes/cascadecohortsync.php | 6 +-
classes/completionscanner.php | 2 +-
classes/contextinfo.php | 12 +++-
classes/form/studyplan_editform.php | 4 +-
lib.php | 91 +++++++++++++++--------------
8 files changed, 98 insertions(+), 79 deletions(-)
diff --git a/classes/aggregator.php b/classes/aggregator.php
index 0c400d3..e984978 100644
--- a/classes/aggregator.php
+++ b/classes/aggregator.php
@@ -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) {
diff --git a/classes/associationservice.php b/classes/associationservice.php
index 0a61ecd..8c11427 100644
--- a/classes/associationservice.php
+++ b/classes/associationservice.php
@@ -106,31 +106,36 @@ class associationservice extends \external_api {
global $DB;
$ctx = \context::instance_by_id($r->contextid);
- $ctxpath = array_reverse($ctx->get_parent_context_ids(true));
- if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
- array_shift($ctxpath);
+ if (is_object($ctx)) {
+ $ctxpath = array_reverse($ctx->get_parent_context_ids(true));
+ if (count($ctxpath) > 1 && $ctxpath[0] == 1) {
+ array_shift($ctxpath);
+ }
+
+ $result = [
+ "id" => $r->id,
+ "name" => $r->name,
+ "idnumber" => $r->idnumber,
+ "description" => $r->description,
+ "visible" => $r->visible,
+ "context" => [
+ "name" => $ctx->get_context_name(false, false),
+ "shortname" => $ctx->get_context_name(false, true),
+ "path" => array_map(function($c) {
+ $cx = (object)\context::instance_by_id($c);
+ return $cx->get_context_name(false, false);
+ }, $ctxpath),
+ "shortpath" => array_map(function($c) {
+ $cx = (object)\context::instance_by_id($c);
+ return $cx->get_context_name(false, true);
+ }, $ctxpath),
+ ],
+ ];
+
+ return $result;
+ } else {
+ throw new \moodle_exception("");
}
-
- $result = [
- "id" => $r->id,
- "name" => $r->name,
- "idnumber" => $r->idnumber,
- "description" => $r->description,
- "visible" => $r->visible,
- "context" => [
- "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);
- }, $ctxpath),
- "shortpath" => array_map(function($c) {
- return \context::instance_by_id($c)->get_context_name(false, true);
- }, $ctxpath),
- ],
- ];
-
- return $result;
-
}
/**
diff --git a/classes/badgeinfo.php b/classes/badgeinfo.php
index 8dc75ad..dcacdff 100644
--- a/classes/badgeinfo.php
+++ b/classes/badgeinfo.php
@@ -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 . '"');
diff --git a/classes/cascadecohortsync.php b/classes/cascadecohortsync.php
index e59baf4..5bee63d 100644
--- a/classes/cascadecohortsync.php
+++ b/classes/cascadecohortsync.php
@@ -103,7 +103,11 @@ class cascadecohortsync {
$groupdata->name = $groupname;
$groupid = groups_create_group($groupdata);
- return $groupid;
+ if (is_int($groupid)) {
+ return $groupid;
+ } else {
+ return 0;
+ }
}
/**
diff --git a/classes/completionscanner.php b/classes/completionscanner.php
index 97ccc62..1429d08 100644
--- a/classes/completionscanner.php
+++ b/classes/completionscanner.php
@@ -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.
diff --git a/classes/contextinfo.php b/classes/contextinfo.php
index 2c4e341..6d2bc77 100644
--- a/classes/contextinfo.php
+++ b/classes/contextinfo.php
@@ -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();
+ }
}
}
diff --git a/classes/form/studyplan_editform.php b/classes/form/studyplan_editform.php
index 2fb6ca7..360482d 100644
--- a/classes/form/studyplan_editform.php
+++ b/classes/form/studyplan_editform.php
@@ -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;
diff --git a/lib.php b/lib.php
index abbf987..c37b300 100644
--- a/lib.php
+++ b/lib.php
@@ -318,56 +318,57 @@ function local_treestudyplan_send_invite($inviteid) {
$noreply = 'noreply@' . get_host_from_url($CFG->wwwroot);
$mailer = get_mailer();
- $mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}");
- $mailer->addAddress($invite->email, $invite->name);
- $mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}");
+ if ($mailer != null ) {
+ $mailer->setFrom($noreply, "{$USER->firstname} {$USER->lastname}");
+ $mailer->addAddress($invite->email, $invite->name);
+ $mailer->addReplyTo($USER->email, "{$USER->firstname} {$USER->lastname}");
- $invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
+ $invitehref = $CFG->wwwroot."/local/treestudyplan/invited.php?key={$invite->invitekey}";
- $data = [ 'permissions' => '',
- 'invitee' => $invite->name,
- 'sender' => "{$USER->firstname} {$USER->lastname}",
- 'link' => $invitehref];
+ $data = [ 'permissions' => '',
+ 'invitee' => $invite->name,
+ 'sender' => "{$USER->firstname} {$USER->lastname}",
+ 'link' => $invitehref];
- if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) {
- $data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan');
- $data['permissions'] .= "\n";
- if ($invite->allow_details) {
- $data['permissions'] .= "- ".get_string('invite_allow_details', 'local_treestudyplan')."
\n";
- }
- if ($invite->allow_calendar) {
- $data['permissions'] .= "- ".get_string('invite_allow_calendar', 'local_treestudyplan')."
\n";
- }
- if ($invite->allow_badges) {
- $data['permissions'] .= "- ".get_string('invite_allow_badges', 'local_treestudyplan')."
\n";
+ if ($invite->allow_details || $invite->allow_calendar || $invite->allow_badges) {
+ $data['permissions'] = get_string('invite_mail_permissions', 'local_treestudyplan');
+ $data['permissions'] .= "\n";
+ if ($invite->allow_details) {
+ $data['permissions'] .= "- ".get_string('invite_allow_details', 'local_treestudyplan')."
\n";
+ }
+ if ($invite->allow_calendar) {
+ $data['permissions'] .= "- ".get_string('invite_allow_calendar', 'local_treestudyplan')."
\n";
+ }
+ if ($invite->allow_badges) {
+ $data['permissions'] .= "- ".get_string('invite_allow_badges', 'local_treestudyplan')."
\n";
+ }
+
+ $data['permissions'] .= "
\n";
}
- $data['permissions'] .= "\n";
+ $body = get_string('invite_mail_text', 'local_treestudyplan', $data);
+ $subject = get_string('invite_mail_subject', 'local_treestudyplan', $data);
+
+ $html = "
+ .
+ .
+
+
+ {$subject}
+
+
+
+ {$body}
+
+ ";
+
+ $mailer->isHTML(true);
+ $mailer->Subject = $subject;
+ $mailer->Body = $html;
+ $mailer->AltBody = strip_tags($body);
+
+ $mailer->send();
}
-
- $body = get_string('invite_mail_text', 'local_treestudyplan', $data);
- $subject = get_string('invite_mail_subject', 'local_treestudyplan', $data);
-
- $html = "
- .
- .
-
-
- {$subject}
-
-
-
- {$body}
-
- ";
-
- $mailer->isHTML(true);
- $mailer->Subject = $subject;
- $mailer->Body = $html;
- $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;
}