| Conditions | 10 |
| Paths | 19 |
| Total Lines | 103 |
| Code Lines | 54 |
| 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 |
||
| 26 | public function courseMenu(FactoryInterface $factory, array $options) |
||
| 27 | { |
||
| 28 | $checker = $this->container->get('security.authorization_checker'); |
||
| 29 | $menu = $factory->createItem('root'); |
||
| 30 | $translator = $this->container->get('translator'); |
||
| 31 | $settingsManager = $this->container->get('chamilo.settings.manager'); |
||
| 32 | |||
| 33 | if ($checker->isGranted('IS_AUTHENTICATED_FULLY')) { |
||
| 34 | $menu->setChildrenAttribute('class', 'nav nav-pills nav-stacked'); |
||
| 35 | $menu->addChild( |
||
| 36 | $translator->trans('MyCourses'), |
||
| 37 | [ |
||
| 38 | 'route' => 'userportal', |
||
| 39 | 'routeParameters' => ['type' => 'courses'], |
||
| 40 | ] |
||
| 41 | ); |
||
| 42 | |||
| 43 | $menu->addChild( |
||
| 44 | $translator->trans('MySessions'), |
||
| 45 | [ |
||
| 46 | 'route' => 'userportal', |
||
| 47 | 'routeParameters' => ['type' => 'sessions'], |
||
| 48 | ] |
||
| 49 | ); |
||
| 50 | |||
| 51 | if (api_is_allowed_to_create_course()) { |
||
| 52 | $lang = $translator->trans('CreateCourse'); |
||
| 53 | if ($settingsManager->getSetting( |
||
| 54 | 'course.course_validation' |
||
| 55 | ) == 'true' |
||
| 56 | ) { |
||
| 57 | $lang = $translator->trans('CreateCourseRequest'); |
||
| 58 | } |
||
| 59 | $menu->addChild( |
||
| 60 | $lang, |
||
| 61 | ['route' => 'add_course'] |
||
| 62 | ); |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($checker->isGranted('ROLE_TEACHER') && |
||
| 66 | $settingsManager->getSetting( |
||
| 67 | 'session.allow_teachers_to_create_sessions' |
||
| 68 | ) |
||
| 69 | ) { |
||
| 70 | |||
| 71 | $menu->addChild( |
||
| 72 | $translator->trans('AddSession'), |
||
| 73 | [ |
||
| 74 | 'route' => 'main', |
||
| 75 | 'routeParameters' => ['name' => 'session/session_add.php'], |
||
| 76 | ] |
||
| 77 | ); |
||
| 78 | } |
||
| 79 | |||
| 80 | $link = $this->container->get('router')->generate('web.main'); |
||
| 81 | |||
| 82 | $menu->addChild( |
||
| 83 | $translator->trans('ManageCourses'), |
||
| 84 | [ |
||
| 85 | 'uri' => $link.'auth/courses.php?action=sortmycourses', |
||
| 86 | ] |
||
| 87 | ); |
||
| 88 | |||
| 89 | $browse = $settingsManager->getSetting( |
||
| 90 | 'display.allow_students_to_browse_courses' |
||
| 91 | ); |
||
| 92 | |||
| 93 | if ($browse == 'true') { |
||
| 94 | if ($checker->isGranted('ROLE_STUDENT') && !api_is_drh( |
||
| 95 | ) && !api_is_session_admin() |
||
| 96 | ) { |
||
| 97 | $menu->addChild( |
||
| 98 | $translator->trans('CourseCatalog'), |
||
| 99 | [ |
||
| 100 | 'uri' => $link.'auth/courses.php', |
||
| 101 | ] |
||
| 102 | ); |
||
| 103 | } else { |
||
| 104 | $menu->addChild( |
||
| 105 | $translator->trans('Dashboard'), |
||
| 106 | [ |
||
| 107 | 'uri' => $link.'dashboard/index.php', |
||
| 108 | ] |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | /** @var \Knp\Menu\MenuItem $menu */ |
||
| 114 | $menu->addChild( |
||
| 115 | $translator->trans('History'), |
||
| 116 | [ |
||
| 117 | 'route' => 'userportal', |
||
| 118 | 'routeParameters' => [ |
||
| 119 | 'type' => 'sessions', |
||
| 120 | 'filter' => 'history', |
||
| 121 | ], |
||
| 122 | ] |
||
| 123 | ); |
||
| 124 | |||
| 125 | } |
||
| 126 | |||
| 127 | return $menu; |
||
| 128 | } |
||
| 129 | |||
| 195 |