Checked phpdoc @return types up to corecompletioninfo.php

This commit is contained in:
PMKuipers 2024-12-27 16:33:33 +01:00
parent 136284368c
commit a0b120df1b

View file

@ -267,7 +267,7 @@ class corecompletioninfo {
$cinfo = [
"type" => $handle,
"aggregation" => self::aggregation_handle($this->completion->get_aggregation_method($type)),
"title" => reset($criterias)->get_type_title(),
"title" => ((object)reset($criterias))->get_type_title(),
"items" => [],
];
@ -465,7 +465,7 @@ class corecompletioninfo {
"aggregation" => self::aggregation_handle($typeaggregation),
"completed" => $completed,
"status" => $completed ? "complete" : "incomplete",
"title" => reset($completions)->get_criteria()->get_type_title(),
"title" => ((object)reset($completions))->get_criteria()->get_type_title(),
"items" => [],
];
@ -524,7 +524,7 @@ class corecompletioninfo {
}
// Determine the grade (retrieve from grade item, not from completion).
$grade = $this->get_grade($cm, $userid);
$grade = (object)$this->get_grade($cm, $userid);
$iinfo['grade'] = $grade->grade;
$iinfo['feedback'] = $grade->feedback;
$iinfo['pending'] = $grade->pending;
@ -586,19 +586,23 @@ class corecompletioninfo {
* Get the grade for a certain course module
* @param \cm_info $cm Course module
* @param int $userid ID of user to retrieve grade for
* @return stdClass|null object containing 'grade' and optional 'feedback' attribute
* @return object object containing 'grade' and optional 'feedback' attribute
*/
private function get_grade($cm, $userid) {
private function get_grade($cm, $userid) : object {
$gi = grade_item::fetch(['itemtype' => 'mod',
'itemmodule' => $cm->modname,
'iteminstance' => $cm->instance,
'courseid' => $this->course->id]); // Make sure we only get results relevant to this course.
if ($gi) {
$result = new \stdClass;
$result->grade = ""; // Fallback code if activity cannot be graded.
$result->feedback = null;
$result->pending = false;
if (is_object($gi)) {
// Only the following types of grade yield a result.
if (($gi->gradetype == GRADE_TYPE_VALUE || $gi->gradetype == GRADE_TYPE_SCALE)) {
$grade = (object)$gi->get_final($userid); // Get the grade for the specified user.
$result = new \stdClass;
// Check if the final grade is available and numeric (safety check).
if (!empty($grade) && !empty($grade->finalgrade) && is_numeric($grade->finalgrade)) {
$result->grade = \grade_format_gradevalue($grade->finalgrade, $gi, true, null, 1);
@ -609,17 +613,16 @@ class corecompletioninfo {
$result->feedback = null;
$result->pending = false;
}
return $result;
}
}
return null; // Activity cannot be graded (Shouldn't be happening, but still....).
return $result;
}
/**
* Get the overall grade for this course
* @param int $grade The grade object to format
* @return stdClass|null object containing 'grade' and optional 'feedback' attribute
* @return string Formatted string of grade value
*/
private function format_course_grade($grade) {
$gi = new \grade_item(['itemtype' => 'course',
@ -636,10 +639,10 @@ class corecompletioninfo {
* Returns the percentage completed by a certain user, returns null if no completion data is available.
*
* @param int $userid The id of the user, 0 for the current user
* @return \stdClass The percentage info, left all 0 if completion is not supported in the course,
* @return object The percentage info, left all 0 if completion is not supported in the course,
* or if there are no activities that support completion.
*/
public function get_advanced_progress_percentage($userid): \stdClass {
public function get_advanced_progress_percentage($userid): object {
// First, let's make sure completion is enabled.
if (!$this->completion->is_enabled()) {