| Conditions | 21 |
| Paths | 7 |
| Total Lines | 114 |
| 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 |
||
| 220 | protected static function getSequence(array $objItems, ?int $categoryId = null, ?string $itemType = null, ?string $coursecode = null, ?array $itemQuestions = null) |
||
| 221 | { |
||
| 222 | $sequences = []; |
||
| 223 | |||
| 224 | switch ($itemType) { |
||
| 225 | case 'quiz': |
||
| 226 | $sequence = []; |
||
| 227 | foreach ($objItems as $objItem) { |
||
| 228 | if (0 === $categoryId) { |
||
| 229 | $questions = []; |
||
| 230 | foreach ($objItem->obj->question_ids as $questionId) { |
||
| 231 | if (isset($itemQuestions[$questionId])) { |
||
| 232 | $questions[$questionId] = $itemQuestions[$questionId]; |
||
| 233 | } |
||
| 234 | } |
||
| 235 | // As weird as this may sound, the constructors for the different object types (found in |
||
| 236 | // src/CourseBundle/Component/CourseCopy/Resources/[objecttype].php) store the object property |
||
| 237 | // in the "obj" attribute. Old code... |
||
| 238 | // So here we recover properties from the quiz object, including questions (array built above). |
||
| 239 | $sequence[$categoryId][$objItem->obj->iid] = [ |
||
| 240 | 'title' => $objItem->obj->title, |
||
| 241 | 'comment' => $objItem->obj->description, |
||
| 242 | 'cc_type' => 'quiz', |
||
| 243 | 'source_id' => $objItem->obj->iid, |
||
| 244 | 'questions' => $questions, |
||
| 245 | 'max_attempt' => $objItem->obj->max_attempt, |
||
| 246 | 'expired_time' => $objItem->obj->expired_time, |
||
| 247 | 'pass_percentage' => $objItem->obj->pass_percentage, |
||
| 248 | 'random_answers' => $objItem->obj->random_answers, |
||
| 249 | 'course_code' => $coursecode, |
||
| 250 | ]; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | $sequences = $sequence[$categoryId]; |
||
| 254 | |||
| 255 | break; |
||
| 256 | |||
| 257 | case 'document': |
||
| 258 | $sequence = []; |
||
| 259 | foreach ($objItems as $objItem) { |
||
| 260 | if (0 === $categoryId) { |
||
| 261 | $sequence[$categoryId][$objItem->source_id] = [ |
||
| 262 | 'title' => $objItem->title, |
||
| 263 | 'comment' => $objItem->comment, |
||
| 264 | 'cc_type' => ('folder' == $objItem->file_type ? 'folder' : 'resource'), |
||
| 265 | 'source_id' => $objItem->source_id, |
||
| 266 | 'path' => $objItem->path, |
||
| 267 | 'file_type' => $objItem->file_type, |
||
| 268 | 'course_code' => $coursecode, |
||
| 269 | ]; |
||
| 270 | } |
||
| 271 | } |
||
| 272 | $sequences = $sequence[$categoryId]; |
||
| 273 | |||
| 274 | break; |
||
| 275 | |||
| 276 | case 'forum': |
||
| 277 | foreach ($objItems as $objItem) { |
||
| 278 | if ($categoryId == $objItem->obj->forum_category) { |
||
| 279 | $sequence[$categoryId][$objItem->obj->forum_id] = [ |
||
| 280 | 'title' => $objItem->obj->forum_title, |
||
| 281 | 'comment' => $objItem->obj->forum_comment, |
||
| 282 | 'cc_type' => 'forum', |
||
| 283 | 'source_id' => $objItem->obj->iid, |
||
| 284 | ]; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | $sequences = $sequence[$categoryId]; |
||
|
|
|||
| 288 | |||
| 289 | break; |
||
| 290 | |||
| 291 | case 'page': |
||
| 292 | foreach ($objItems as $objItem) { |
||
| 293 | if (0 === $categoryId) { |
||
| 294 | $sequence[$categoryId][$objItem->page_id] = [ |
||
| 295 | 'title' => $objItem->title, |
||
| 296 | 'comment' => $objItem->content, |
||
| 297 | 'cc_type' => 'page', |
||
| 298 | 'source_id' => $objItem->page_id, |
||
| 299 | 'reflink' => $objItem->reflink, |
||
| 300 | ]; |
||
| 301 | } |
||
| 302 | } |
||
| 303 | $sequences = $sequence[$categoryId]; |
||
| 304 | |||
| 305 | break; |
||
| 306 | |||
| 307 | case 'link': |
||
| 308 | if (!isset($categoryId)) { |
||
| 309 | $categories = []; |
||
| 310 | foreach ($objItems as $objItem) { |
||
| 311 | $categories[$objItem->category_id] = self::getSequence($objItems, $objItem->category_id, $itemType); |
||
| 312 | } |
||
| 313 | $sequences = $categories; |
||
| 314 | } else { |
||
| 315 | foreach ($objItems as $objItem) { |
||
| 316 | if ($categoryId == $objItem->category_id) { |
||
| 317 | $sequence[$categoryId][$objItem->source_id] = [ |
||
| 318 | 'title' => $objItem->title, |
||
| 319 | 'comment' => $objItem->description, |
||
| 320 | 'cc_type' => 'url', |
||
| 321 | 'source_id' => $objItem->source_id, |
||
| 322 | 'url' => $objItem->url, |
||
| 323 | 'target' => $objItem->target, |
||
| 324 | ]; |
||
| 325 | } |
||
| 326 | } |
||
| 327 | $sequences = $sequence[$categoryId]; |
||
| 328 | } |
||
| 329 | |||
| 330 | break; |
||
| 331 | } |
||
| 332 | |||
| 333 | return $sequences; |
||
| 334 | } |
||
| 385 |