Typecast the return value of MultichoiceResponse::score to int

Created on 15 April 2022, almost 3 years ago
Updated 26 July 2024, 9 months ago

In the previous versions of the module it was possible to create the multichoice qiuz question with empty score field for the correct answer.
Now module prevents that on the form level, but if you had questions created before you can face the situation when selecting the correct answer causes this error:

Return value of Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::score() must be of the type int or null, string returned in Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse->score()

That happens because code on in MultichoiceResponse::score (line 73)

$score = $alternative->get('multichoice_score_chosen')->getString();

Can return the empty string and empty string isn't converted to 0 and doesn't comply with the function signature:

public function score(array $response): ?int
πŸ› Bug report
Status

Closed: outdated

Version

6.0

Component

Code - Multichoice

Created by

πŸ‡ΊπŸ‡¦Ukraine artem_sylchuk Lutsk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024