Passed
Push — master ( ca27a7...8ba864 )
by
unknown
17:12 queued 08:14
created

Ims2Question::setAnswer()   C

Complexity

Conditions 14
Paths 144

Size

Total Lines 51
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 33
nc 144
nop 0
dl 0
loc 51
rs 5.9
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * @author Claro Team <[email protected]>
7
 * @author Yannick Warnier <[email protected]> -
8
 * updated ImsAnswerHotspot to match QTI norms
9
 */
10
class Ims2Question extends Question
11
{
12
    /**
13
     * Create the proper Answer handler.
14
     * Messages/strings in code must be English.
15
     */
16
    public function setAnswer()
17
    {
18
        $questionId = 0;
19
20
        if (method_exists($this, 'getIid')) {
21
            $questionId = (int) $this->getIid();
22
        } elseif (property_exists($this, 'iid')) {
23
            $questionId = (int) $this->iid;
24
        } elseif (property_exists($this, 'id')) {
25
            $questionId = (int) $this->id;
26
        }
27
28
        // Avoid null IDs: use 0 as safe fallback (some flows set the ID later).
29
        if ($questionId < 0) {
30
            $questionId = 0;
31
        }
32
33
        switch ($this->type) {
34
            case TF:
35
            case MCUA:
36
            case MCMA:
37
                $answer = new ImsAnswerMultipleChoice($questionId);
38
                break;
39
40
            case FIB:
41
                $answer = new ImsAnswerFillInBlanks($questionId);
42
                break;
43
44
            case MATCHING:
45
            case MATCHING_DRAGGABLE:
46
                $answer = new ImsAnswerMatching($questionId);
47
                break;
48
49
            case FREE_ANSWER:
50
                $answer = new ImsAnswerFree($questionId);
51
                break;
52
53
            case HOT_SPOT:
54
                $answer = new ImsAnswerHotspot($questionId);
55
                break;
56
57
            default:
58
                $answer = null;
59
        }
60
61
        // If the parent Question class expects an internal property, keep it.
62
        if (property_exists($this, 'answer')) {
63
            $this->answer = $answer;
64
        }
65
66
        return $answer;
67
    }
68
69
    public function createAnswersForm($form)
70
    {
71
        return true;
72
    }
73
74
    public function processAnswersCreation($form, $exercise)
75
    {
76
        return true;
77
    }
78
}
79