| Conditions | 15 |
| Paths | 160 |
| Total Lines | 139 |
| Code Lines | 99 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 83 | public function aboutAction(Course $course): Response |
||
| 84 | { |
||
| 85 | $courseId = $course->getId(); |
||
| 86 | $userId = $this->getUser()->getId(); |
||
| 87 | |||
| 88 | $em = $this->getDoctrine()->getManager(); |
||
| 89 | |||
| 90 | $fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField'); |
||
| 91 | $fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag'); |
||
| 92 | |||
| 93 | /** @var CCourseDescription $courseDescription */ |
||
| 94 | $courseDescriptionTools = $em->getRepository('ChamiloCourseBundle:CCourseDescription') |
||
| 95 | ->findBy( |
||
| 96 | [ |
||
| 97 | 'cId' => $course->getId(), |
||
| 98 | 'sessionId' => 0, |
||
| 99 | ], |
||
| 100 | [ |
||
| 101 | 'id' => 'DESC', |
||
| 102 | 'descriptionType' => 'ASC', |
||
| 103 | ] |
||
| 104 | ); |
||
| 105 | |||
| 106 | $courseValues = new \ExtraFieldValue('course'); |
||
| 107 | |||
| 108 | $urlCourse = api_get_path(WEB_PATH)."course/$courseId/about"; |
||
| 109 | $courseTeachers = $course->getTeachers(); |
||
| 110 | $teachersData = []; |
||
| 111 | |||
| 112 | /** @var CourseRelUser $teacherSubscription */ |
||
| 113 | foreach ($courseTeachers as $teacherSubscription) { |
||
| 114 | $teacher = $teacherSubscription->getUser(); |
||
| 115 | $userData = [ |
||
| 116 | 'complete_name' => UserManager::formatUserFullName($teacher), |
||
| 117 | 'image' => UserManager::getUserPicture( |
||
| 118 | $teacher->getId(), |
||
| 119 | USER_IMAGE_SIZE_ORIGINAL |
||
| 120 | ), |
||
| 121 | 'diploma' => $teacher->getDiplomas(), |
||
| 122 | 'openarea' => $teacher->getOpenarea(), |
||
| 123 | ]; |
||
| 124 | |||
| 125 | $teachersData[] = $userData; |
||
| 126 | } |
||
| 127 | |||
| 128 | $tagField = $fieldsRepo->findOneBy([ |
||
| 129 | 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE, |
||
| 130 | 'variable' => 'tags', |
||
| 131 | ]); |
||
| 132 | |||
| 133 | $courseTags = []; |
||
| 134 | |||
| 135 | if (!is_null($tagField)) { |
||
| 136 | $courseTags = $fieldTagsRepo->getTags($tagField, $courseId); |
||
| 137 | } |
||
| 138 | |||
| 139 | $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = $courseMaterial = $courseResources = $courseAssessment = ''; |
||
| 140 | $courseCustom = []; |
||
| 141 | foreach ($courseDescriptionTools as $descriptionTool) { |
||
| 142 | switch ($descriptionTool->getDescriptionType()) { |
||
| 143 | case CCourseDescription::TYPE_DESCRIPTION: |
||
| 144 | $courseDescription = $descriptionTool->getContent(); |
||
| 145 | break; |
||
| 146 | case CCourseDescription::TYPE_OBJECTIVES: |
||
| 147 | $courseObjectives = $descriptionTool; |
||
| 148 | break; |
||
| 149 | case CCourseDescription::TYPE_TOPICS: |
||
| 150 | $courseTopics = $descriptionTool; |
||
| 151 | break; |
||
| 152 | case CCourseDescription::TYPE_METHODOLOGY: |
||
| 153 | $courseMethodology = $descriptionTool; |
||
| 154 | break; |
||
| 155 | case CCourseDescription::TYPE_COURSE_MATERIAL: |
||
| 156 | $courseMaterial = $descriptionTool; |
||
| 157 | break; |
||
| 158 | case CCourseDescription::TYPE_RESOURCES: |
||
| 159 | $courseResources = $descriptionTool; |
||
| 160 | break; |
||
| 161 | case CCourseDescription::TYPE_ASSESSMENT: |
||
| 162 | $courseAssessment = $descriptionTool; |
||
| 163 | break; |
||
| 164 | case CCourseDescription::TYPE_CUSTOM: |
||
| 165 | $courseCustom[] = $descriptionTool; |
||
| 166 | break; |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | $topics = [ |
||
| 171 | 'objectives' => $courseObjectives, |
||
| 172 | 'topics' => $courseTopics, |
||
| 173 | 'methodology' => $courseMethodology, |
||
| 174 | 'material' => $courseMaterial, |
||
| 175 | 'resources' => $courseResources, |
||
| 176 | 'assessment' => $courseAssessment, |
||
| 177 | 'custom' => array_reverse($courseCustom), |
||
| 178 | ]; |
||
| 179 | |||
| 180 | $subscriptionUser = \CourseManager::is_user_subscribed_in_course($userId, $course->getCode()); |
||
| 181 | |||
| 182 | $allowSubscribe = false; |
||
| 183 | if ($course->getSubscribe() || api_is_platform_admin()) { |
||
| 184 | $allowSubscribe = true; |
||
| 185 | } |
||
| 186 | $plugin = \BuyCoursesPlugin::create(); |
||
| 187 | $checker = $plugin->isEnabled(); |
||
| 188 | $courseIsPremium = null; |
||
| 189 | if ($checker) { |
||
| 190 | $courseIsPremium = $plugin->getItemByProduct( |
||
| 191 | $courseId, |
||
| 192 | \BuyCoursesPlugin::PRODUCT_TYPE_COURSE |
||
| 193 | ); |
||
| 194 | } |
||
| 195 | |||
| 196 | $image = Container::getIllustrationRepository()->getIllustrationUrl($course, 'course_picture_medium'); |
||
| 197 | $params = [ |
||
| 198 | 'course' => $course, |
||
| 199 | 'description' => $courseDescription, |
||
| 200 | 'image' => $image, |
||
| 201 | 'syllabus' => $topics, |
||
| 202 | 'tags' => $courseTags, |
||
| 203 | 'teachers' => $teachersData, |
||
| 204 | 'extra_fields' => $courseValues->getAllValuesForAnItem( |
||
| 205 | $course->getId(), |
||
| 206 | null, |
||
| 207 | true |
||
| 208 | ), |
||
| 209 | 'subscription' => $subscriptionUser, |
||
| 210 | ]; |
||
| 211 | |||
| 212 | $metaInfo = '<meta property="og:url" content="'.$urlCourse.'" />'; |
||
| 213 | $metaInfo .= '<meta property="og:type" content="website" />'; |
||
| 214 | $metaInfo .= '<meta property="og:title" content="'.$course->getTitle().'" />'; |
||
| 215 | $metaInfo .= '<meta property="og:description" content="'.strip_tags($courseDescription).'" />'; |
||
| 216 | $metaInfo .= '<meta property="og:image" content="'.$image.'" />'; |
||
| 217 | |||
| 218 | $htmlHeadXtra[] = $metaInfo; |
||
| 219 | $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); |
||
| 220 | |||
| 221 | return $this->render('@ChamiloTheme/Course/about.html.twig', [$params]); |
||
| 222 | } |
||
| 226 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.