Conditions | 3 |
Paths | 3 |
Total Lines | 57 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
44 | public function onGenerateAnswers() |
||
45 | { |
||
46 | //add responses holder |
||
47 | $qresponseLid = new CcResponseLidtype(); |
||
48 | $this->qresponseLid = $qresponseLid; |
||
49 | $this->qpresentation->setResponseLid($qresponseLid); |
||
50 | $qresponseChoice = new CcAssesmentRenderFibtype(); |
||
51 | $qresponseLid->setRenderFib($qresponseChoice); |
||
52 | |||
53 | //Mark that question has more than one correct answer |
||
54 | $qresponseLid->setRcardinality(CcQtiValues::MULTIPLE); |
||
55 | |||
56 | //are we to shuffle the responses? |
||
57 | $shuffleAnswers = $this->quiz['random_answers'] > 0; |
||
58 | |||
59 | $qresponseChoice->enableShuffle($shuffleAnswers); |
||
60 | $answerlist = []; |
||
61 | |||
62 | $qaResponses = $this->questionNode->answers; |
||
63 | |||
64 | foreach ($qaResponses as $node) { |
||
65 | $answerContent = $node['answer']; |
||
66 | $answerGradeFraction = $node['ponderation']; |
||
67 | |||
68 | $result = CcHelpers::processLinkedFiles($answerContent, |
||
69 | $this->manifest, |
||
70 | $this->rootpath, |
||
71 | $this->contextid, |
||
72 | $this->outdir); |
||
73 | |||
74 | $qresponseLabel = CcAssesmentHelper::addAnswer($qresponseChoice, |
||
75 | $result[0], |
||
76 | CcQtiValues::HTMLTYPE); |
||
77 | |||
78 | PkgResourceDependencies::instance()->add($result[1]); |
||
79 | |||
80 | $answerIdent = $qresponseLabel->getIdent(); |
||
81 | $feedbackIdent = $answerIdent.'_fb'; |
||
82 | //add answer specific feedbacks if not empty |
||
83 | $content = $node['comment']; |
||
84 | if (!empty($content)) { |
||
85 | $result = CcHelpers::processLinkedFiles($content, |
||
86 | $this->manifest, |
||
87 | $this->rootpath, |
||
88 | $this->contextid, |
||
89 | $this->outdir); |
||
90 | |||
91 | CcAssesmentHelper::addFeedback($this->qitem, |
||
92 | $result[0], |
||
93 | CcQtiValues::HTMLTYPE, |
||
94 | $feedbackIdent); |
||
95 | |||
96 | PkgResourceDependencies::instance()->add($result[1]); |
||
97 | } |
||
98 | $answerlist[$answerIdent] = [$feedbackIdent, ($answerGradeFraction > 0)]; |
||
99 | } |
||
100 | $this->answerlist = $answerlist; |
||
101 | } |
||
122 |