Conditions | 21 |
Paths | 7 |
Total Lines | 100 |
Code Lines | 77 |
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 |
||
146 | protected static function getSequence($objItems, $categoryId = null, $itemType = null, $coursecode = null, $itemQuestions = null) |
||
147 | { |
||
148 | $sequences = []; |
||
149 | switch ($itemType) { |
||
150 | case 'quiz': |
||
151 | $sequence = []; |
||
152 | foreach ($objItems as $objItem) { |
||
153 | if ($categoryId === 0) { |
||
154 | $questions = []; |
||
155 | foreach ($objItem->obj->question_ids as $questionId) { |
||
156 | if (isset($itemQuestions[$questionId])) { |
||
157 | $questions[$questionId] = $itemQuestions[$questionId]; |
||
158 | } |
||
159 | } |
||
160 | $sequence[$categoryId][$objItem->obj->iid] = [ |
||
161 | 'title' => $objItem->obj->title, |
||
162 | 'comment' => $objItem->obj->description, |
||
163 | 'cc_type' => 'quiz', |
||
164 | 'source_id' => $objItem->obj->iid, |
||
165 | 'questions' => $questions, |
||
166 | 'max_attempt' => $objItem->obj->max_attempt, |
||
167 | 'expired_time' => $objItem->obj->expired_time, |
||
168 | 'pass_percentage' => $objItem->obj->pass_percentage, |
||
169 | 'random_answers' => $objItem->obj->random_answers, |
||
170 | 'course_code' => $coursecode, |
||
171 | ]; |
||
172 | } |
||
173 | } |
||
174 | $sequences = $sequence[$categoryId]; |
||
175 | break; |
||
176 | case 'document': |
||
177 | $sequence = []; |
||
178 | foreach ($objItems as $objItem) { |
||
179 | if ($categoryId === 0) { |
||
180 | $sequence[$categoryId][$objItem->source_id] = [ |
||
181 | 'title' => $objItem->title, |
||
182 | 'comment' => $objItem->comment, |
||
183 | 'cc_type' => ($objItem->file_type == 'folder' ? 'folder' : 'resource'), |
||
184 | 'source_id' => $objItem->source_id, |
||
185 | 'path' => $objItem->path, |
||
186 | 'file_type' => $objItem->file_type, |
||
187 | 'course_code' => $coursecode, |
||
188 | ]; |
||
189 | } |
||
190 | } |
||
191 | $sequences = $sequence[$categoryId]; |
||
192 | break; |
||
193 | case 'forum': |
||
194 | foreach ($objItems as $objItem) { |
||
195 | if ($categoryId == $objItem->obj->forum_category) { |
||
196 | $sequence[$categoryId][$objItem->obj->forum_id] = [ |
||
197 | 'title' => $objItem->obj->forum_title, |
||
198 | 'comment' => $objItem->obj->forum_comment, |
||
199 | 'cc_type' => 'forum', |
||
200 | 'source_id' => $objItem->obj->iid, |
||
201 | ]; |
||
202 | } |
||
203 | } |
||
204 | $sequences = $sequence[$categoryId]; |
||
|
|||
205 | break; |
||
206 | case 'page': |
||
207 | foreach ($objItems as $objItem) { |
||
208 | if ($categoryId === 0) { |
||
209 | $sequence[$categoryId][$objItem->page_id] = [ |
||
210 | 'title' => $objItem->title, |
||
211 | 'comment' => $objItem->content, |
||
212 | 'cc_type' => 'page', |
||
213 | 'source_id' => $objItem->page_id, |
||
214 | 'reflink' => $objItem->reflink, |
||
215 | ]; |
||
216 | } |
||
217 | } |
||
218 | $sequences = $sequence[$categoryId]; |
||
219 | break; |
||
220 | case 'link': |
||
221 | if (!isset($categoryId)) { |
||
222 | $categories = []; |
||
223 | foreach ($objItems as $objItem) { |
||
224 | $categories[$objItem->category_id] = self::getSequence($objItems, $objItem->category_id, $itemType); |
||
225 | } |
||
226 | $sequences = $categories; |
||
227 | } else { |
||
228 | foreach ($objItems as $objItem) { |
||
229 | if ($categoryId == $objItem->category_id) { |
||
230 | $sequence[$categoryId][$objItem->source_id] = [ |
||
231 | 'title' => $objItem->title, |
||
232 | 'comment' => $objItem->description, |
||
233 | 'cc_type' => 'url', |
||
234 | 'source_id' => $objItem->source_id, |
||
235 | 'url' => $objItem->url, |
||
236 | 'target' => $objItem->target, |
||
237 | ]; |
||
238 | } |
||
239 | } |
||
240 | $sequences = $sequence[$categoryId]; |
||
241 | } |
||
242 | break; |
||
243 | } |
||
244 | |||
245 | return $sequences; |
||
246 | } |
||
292 |