| Conditions | 7 |
| Paths | 16 |
| Total Lines | 101 |
| 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 |
||
| 20 | public static function unserialize($type, $serialized, $ignoreErrors = false) |
||
| 21 | { |
||
| 22 | $allowedClasses = []; |
||
| 23 | |||
| 24 | switch ($type) { |
||
| 25 | case 'career': |
||
| 26 | case 'sequence_graph': |
||
| 27 | $allowedClasses = [ |
||
| 28 | \Fhaculty\Graph\Graph::class, |
||
| 29 | \Fhaculty\Graph\Set\VerticesMap::class, |
||
| 30 | \Fhaculty\Graph\Set\Vertices::class, |
||
| 31 | \Fhaculty\Graph\Set\Edges::class, |
||
| 32 | \Fhaculty\Graph\Vertex::class, |
||
| 33 | \Fhaculty\Graph\Edge\Base::class, |
||
| 34 | \Fhaculty\Graph\Edge\Directed::class, |
||
| 35 | \Fhaculty\Graph\Edge\Undirected::class, |
||
| 36 | ]; |
||
| 37 | break; |
||
| 38 | case 'course': |
||
| 39 | $allowedClasses = [ |
||
| 40 | \Chamilo\CourseBundle\Component\CourseCopy\Course::class, |
||
| 41 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Announcement::class, |
||
| 42 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Asset::class, |
||
| 43 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Attendance::class, |
||
| 44 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\CalendarEvent::class, |
||
| 45 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyLearnpath::class, |
||
| 46 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseCopyTestCategory::class, |
||
| 47 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseDescription::class, |
||
| 48 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\CourseSession::class, |
||
| 49 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Document::class, |
||
| 50 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Forum::class, |
||
| 51 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumCategory::class, |
||
| 52 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumPost::class, |
||
| 53 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\ForumTopic::class, |
||
| 54 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Glossary::class, |
||
| 55 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\GradeBookBackup::class, |
||
| 56 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\LearnPathCategory::class, |
||
| 57 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Link::class, |
||
| 58 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\LinkCategory::class, |
||
| 59 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Quiz::class, |
||
| 60 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestion::class, |
||
| 61 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\QuizQuestionOption::class, |
||
| 62 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\ScormDocument::class, |
||
| 63 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Survey::class, |
||
| 64 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyInvitation::class, |
||
| 65 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\SurveyQuestion::class, |
||
| 66 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Thematic::class, |
||
| 67 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\ToolIntro::class, |
||
| 68 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Wiki::class, |
||
| 69 | \Chamilo\CourseBundle\Component\CourseCopy\Resources\Work::class, |
||
| 70 | \Chamilo\CourseBundle\Entity\CLpCategory::class, |
||
| 71 | stdClass::class, |
||
| 72 | Category::class, |
||
| 73 | AttendanceLink::class, |
||
| 74 | DropboxLink::class, |
||
| 75 | Evaluation::class, |
||
| 76 | ExerciseLink::class, |
||
| 77 | ForumThreadLink::class, |
||
| 78 | LearnpathLink::class, |
||
| 79 | LinkFactory::class, |
||
| 80 | Result::class, |
||
| 81 | StudentPublicationLink::class, |
||
| 82 | SurveyLink::class, |
||
| 83 | ]; |
||
| 84 | // no break |
||
| 85 | case 'lp': |
||
| 86 | $allowedClasses = array_merge( |
||
| 87 | $allowedClasses, |
||
| 88 | [ |
||
| 89 | learnpath::class, |
||
| 90 | learnpathItem::class, |
||
| 91 | aicc::class, |
||
| 92 | aiccBlock::class, |
||
| 93 | aiccItem::class, |
||
| 94 | aiccObjective::class, |
||
| 95 | aiccResource::class, |
||
| 96 | scorm::class, |
||
| 97 | scormItem::class, |
||
| 98 | scormMetadata::class, |
||
| 99 | scormOrganization::class, |
||
| 100 | scormResource::class, |
||
| 101 | Link::class, |
||
| 102 | LpItem::class, |
||
| 103 | ] |
||
| 104 | ); |
||
| 105 | break; |
||
| 106 | case 'not_allowed_classes': |
||
| 107 | default: |
||
| 108 | $allowedClasses = false; |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($ignoreErrors) { |
||
| 112 | return @Unserialize::unserialize( |
||
| 113 | $serialized, |
||
| 114 | ['allowed_classes' => $allowedClasses] |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | |||
| 118 | return Unserialize::unserialize( |
||
| 119 | $serialized, |
||
| 120 | ['allowed_classes' => $allowedClasses] |
||
| 121 | ); |
||
| 124 |