Conditions | 28 |
Paths | 70 |
Total Lines | 123 |
Code Lines | 87 |
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 |
||
51 | private function generateActivityDefinitionFromQuestionType() |
||
52 | { |
||
53 | $languageIso = api_get_language_isocode(); |
||
54 | $courseId = api_get_course_int_id(); |
||
55 | |||
56 | $questionTitle = strip_tags($this->question->getQuestion()); |
||
57 | $questionTitle = trim($questionTitle); |
||
58 | $questionDescription = strip_tags($this->question->getDescription()); |
||
59 | $questionDescription = trim($questionDescription); |
||
60 | |||
61 | $titleMap = LanguageMap::create([$languageIso => $questionTitle]); |
||
62 | $descriptionMap = $questionDescription ? LanguageMap::create([$languageIso => $questionDescription]) : null; |
||
63 | |||
64 | $objAnswer = new Answer($this->question->getId(), $courseId); |
||
65 | $objAnswer->read(); |
||
66 | |||
67 | $type = IRI::fromString('http://adlnet.gov/expapi/activities/question'); |
||
68 | |||
69 | switch ($this->question->getType()) { |
||
70 | case MULTIPLE_ANSWER: |
||
71 | case UNIQUE_ANSWER: |
||
72 | case UNIQUE_ANSWER_IMAGE: |
||
73 | case READING_COMPREHENSION: |
||
74 | $choices = []; |
||
75 | $correctResponsesPattern = []; |
||
76 | |||
77 | for ($i = 1; $i <= $objAnswer->nbrAnswers; $i++) { |
||
78 | $choices[] = new InteractionComponent( |
||
79 | $objAnswer->iid[$i], |
||
80 | LanguageMap::create([$languageIso => $objAnswer->selectAnswer($i)]) |
||
81 | ); |
||
82 | |||
83 | if ($objAnswer->isCorrect($i)) { |
||
84 | $correctResponsesPattern[] = $objAnswer->iid[$i]; |
||
85 | } |
||
86 | } |
||
87 | |||
88 | return new ChoiceInteractionDefinition( |
||
89 | $titleMap, |
||
90 | $descriptionMap, |
||
91 | $type, |
||
92 | null, |
||
93 | null, |
||
94 | [implode('[,]', $correctResponsesPattern)], |
||
95 | $choices |
||
96 | ); |
||
97 | |||
98 | case DRAGGABLE: |
||
99 | $choices = []; |
||
100 | |||
101 | for ($i = 1; $i <= $objAnswer->nbrAnswers; $i++) { |
||
102 | if ((int) $objAnswer->correct[$i] > 0) { |
||
103 | $choices[] = new InteractionComponent( |
||
104 | $objAnswer->correct[$i], |
||
105 | LanguageMap::create([$languageIso => $objAnswer->answer[$i]]) |
||
106 | ); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | $correctResponsesPattern = \array_slice($objAnswer->autoId, 0, $objAnswer->nbrAnswers / 2); |
||
111 | |||
112 | return new SequencingInteractionDefinition( |
||
113 | $titleMap, |
||
114 | $descriptionMap, |
||
115 | $type, |
||
116 | null, |
||
117 | null, |
||
118 | [implode('[,]', $correctResponsesPattern)], |
||
119 | $choices |
||
120 | ); |
||
121 | |||
122 | case MATCHING: |
||
123 | case MATCHING_DRAGGABLE: |
||
124 | /** @var array|InteractionComponent[] $source */ |
||
125 | $source = []; |
||
126 | |||
127 | /** @var array|InteractionComponent[] $source */ |
||
128 | $target = []; |
||
129 | $correctResponsesPattern = []; |
||
130 | |||
131 | for ($i = 1; $i <= $objAnswer->nbrAnswers; $i++) { |
||
132 | $interactionComponent = new InteractionComponent( |
||
133 | $objAnswer->selectAutoId($i), |
||
134 | LanguageMap::create([$languageIso => $objAnswer->selectAnswer($i)]) |
||
135 | ); |
||
136 | |||
137 | if ((int) $objAnswer->correct[$i] > 0) { |
||
138 | $source[] = $interactionComponent; |
||
139 | |||
140 | $correctResponsesPattern[] = $objAnswer->selectAutoId($i).'[.]'.$objAnswer->correct[$i]; |
||
141 | } else { |
||
142 | $target[] = $interactionComponent; |
||
143 | } |
||
144 | } |
||
145 | |||
146 | return new MatchingInteractionDefinition( |
||
147 | $titleMap, |
||
148 | $descriptionMap, |
||
149 | $type, |
||
150 | null, |
||
151 | null, |
||
152 | [implode('[,]', $correctResponsesPattern)], |
||
153 | $source, |
||
154 | $target |
||
155 | ); |
||
156 | |||
157 | case FREE_ANSWER: |
||
158 | return new LongFillInInteractionDefinition($titleMap, $descriptionMap, $type); |
||
159 | |||
160 | case FILL_IN_BLANKS: |
||
161 | case HOT_SPOT: |
||
162 | case HOT_SPOT_DELINEATION: |
||
163 | case MULTIPLE_ANSWER_COMBINATION: |
||
164 | case UNIQUE_ANSWER_NO_OPTION: |
||
165 | case MULTIPLE_ANSWER_TRUE_FALSE: |
||
166 | case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY: |
||
167 | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
||
168 | case GLOBAL_MULTIPLE_ANSWER: |
||
169 | case CALCULATED_ANSWER: |
||
170 | case ANNOTATION: |
||
171 | case ORAL_EXPRESSION: |
||
172 | default: |
||
173 | return new OtherInteractionDefinition($titleMap, $descriptionMap, $type); |
||
174 | } |
||
177 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.