bugfix #39505: TypeError in SelfRegistration with reg-code & local roles
The PR fixes 3 TypeErrors for issue: https://mantis.ilias.de/view.php?id=39505 forum: https://docu.ilias.de/goto_docu_frm_1875_8811.html .
Thx for the PR @utesche . I suggest to cast the values in the variable assingment.
Instead of:
$code_local_roles = [];
AND
$code_data = ilRegistrationCode::getCodeData($code);
if ($code_data["role_local"]) {
// need user id before we can assign role(s)
$code_local_roles = explode(";", $code_data["role_local"]);
}
Should: All values of the $code_local_roles list should be of type int.
/** @var list<int>|null $code_local_roles */
$code_local_roles = [];
AND
$code_data = ilRegistrationCode::getCodeData($code);
if (isset($code_data['role_local']) && is_string($code_data['role_local'])) {
// need user id before we can assign role(s)
$code_local_roles = array_filter(array_map(
static fn (string $value): int => (int) $value,
explode(';', $code_data['role_local'])
));
}
Whenever $code_local_roles is used, the consuming code can expect all values to be of type int.
Of course, it is still not nice that consumers (like class.ilAccountRegistrationGUI.php) have to know internals (separator) of $code_data['role_local']. But that should not be part of this PR, this requires some deep refactorings.
Best regards, Michael
@utesche Do have time/energy and want to include the review remarks into your PR?
@mjansenDatabay, as suggested, the strict casting to int of separate local_role_ids at usage time is changed now to a conversion of the whole array of ids to int when creating the array (by exploding the given input).
@pascalseeland Please check my suggested change and merge the PR afterwards, if you don't have any further objections.