Description
Following the changes introduced in MDL-79280, where the parameter type hint for the constructor in various classes was updated from stdClass to cm_info, some related files were not updated accordingly.
For example, in attempts_report_options, the constructor is still declared to accept a stdClass, but internally the method expects properties and behaviors specific to the cm_info class. This leads to a type error when using this class in reports or modules that pass a cm_info instance, as intended by the updated design.
This inconsistency results in the following error:
TypeError: Argument 1 passed to attempts_report_options::__construct() must be an instance of stdClass, instance of cm_info given.
|
Expected Behavior
All related class constructors (including attempts_report_options) should accept cm_info instead of stdClass to remain consistent with MDL-79280 and to support improved type safety.
Actual Behavior
Constructor signature expects stdClass, which is no longer valid in this context and causes an exception when the actual cm_info object is passed.
The issue can be further demonstrated with PHP unit. In the quiz_settings class, change the constructor to:
public function __construct($quiz, stdClass $cm, $course, $getcontext = true) { |
Then run the quiz testsuite in PHPUnit and observe the following error:
1) mod_quiz\attempt_test::test_attempt_url
|
TypeError: mod_quiz\quiz_settings::__construct(): Argument #2 ($cm) must be of type stdClass, cm_info given, called in mod/quiz/classes/quiz_settings.php on line 106
|
Now change the constructor to:
public function __construct($quiz, cm_info $cm, $course, $getcontext = true) { |
And run PHPUnit again:
1) mod_quiz\attempt_test::test_attempt_url
|
TypeError: mod_quiz\quiz_settings::__construct(): Argument #2 ($cm) must be of type cm_info, stdClass given, called in mod/quiz/classes/quiz_attempt.php on line 148
|
So by enforcing the type, we can reveal sometimes it is passed an stdClass, and sometimes it is passed a cm_info. Presumably it should always be passed a cm_info so we should update those places in core that are passing an stdClass to pass a true cm_info object, and also update the docblock.
Impact
This affects any custom reports or plugins relying on attempts_report_options and similar classes, breaking backward compatibility introduced unintentionally by a partial refactor.