| Conditions | 30 |
| Paths | 2563 |
| Total Lines | 82 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 26 | public function check( |
||
| 27 | bool $tutor = false, |
||
| 28 | bool $coach = false, |
||
| 29 | bool $sessionCoach = false, |
||
| 30 | bool $checkStudentView = true, |
||
| 31 | ?Course $course = null, |
||
| 32 | ?Session $session = null, |
||
| 33 | ): bool { |
||
| 34 | /** @var User $user */ |
||
| 35 | $user = $this->security->getUser(); |
||
| 36 | |||
| 37 | $studentViewIsActive = 'studentview' === $this->requestStack->getSession()->get('studentview'); |
||
| 38 | |||
| 39 | $isSessionAdminAllowedToEdit = 'true' === $this->settingsManager->getSetting('session.session_admins_edit_courses_content'); |
||
| 40 | |||
| 41 | if ($user->isAdmin() || ($user->isSessionAdmin() && $isSessionAdminAllowedToEdit)) { |
||
| 42 | if ($checkStudentView && $studentViewIsActive) { |
||
| 43 | return false; |
||
| 44 | } |
||
| 45 | |||
| 46 | return true; |
||
| 47 | } |
||
| 48 | |||
| 49 | $session = $session ?: $this->cidReqHelper->getSessionEntity(); |
||
| 50 | $course = $course ?: $this->cidReqHelper->getCourseEntity(); |
||
| 51 | |||
| 52 | if ($session && $course && 'true' === $this->settingsManager->getSetting('session.session_courses_read_only_mode')) { |
||
| 53 | $lockExrafieldField = (new ExtraFieldValue('course')) |
||
| 54 | ->get_values_by_handler_and_field_variable( |
||
| 55 | $course->getId(), |
||
| 56 | 'session_courses_read_only_mode' |
||
| 57 | ) |
||
| 58 | ; |
||
| 59 | |||
| 60 | if (!empty($lockExrafieldField['value'])) { |
||
| 61 | return false; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | $isCoachAllowedToEdit = $session?->hasCoach($user) && !$studentViewIsActive; |
||
| 66 | $sessionVisibility = $session?->setAccessVisibilityByUser($user); |
||
| 67 | $isCourseAdmin = $user->hasRole('ROLE_CURRENT_COURSE_TEACHER') || $user->hasRole('ROLE_CURRENT_COURSE_SESSION_TEACHER'); |
||
| 68 | |||
| 69 | if (!$isCourseAdmin && $tutor) { |
||
| 70 | $isCourseAdmin = $user->isCourseTutor($course, $session); |
||
| 71 | } |
||
| 72 | |||
| 73 | if (!$isCourseAdmin && $coach) { |
||
| 74 | if (Session::READ_ONLY === $sessionVisibility) { |
||
| 75 | $isCoachAllowedToEdit = false; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ('true' === $this->settingsManager->getSetting('session.allow_coach_to_edit_course_session')) { |
||
| 79 | $isCourseAdmin = $isCoachAllowedToEdit; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!$isCourseAdmin && $sessionCoach) { |
||
| 84 | $isCourseAdmin = $isCoachAllowedToEdit; |
||
| 85 | } |
||
| 86 | |||
| 87 | if ('true' !== $this->settingsManager->getSetting('course.student_view_enabled')) { |
||
| 88 | return $isCourseAdmin; |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($session) { |
||
| 92 | if (Session::READ_ONLY === $sessionVisibility) { |
||
| 93 | $isCoachAllowedToEdit = false; |
||
| 94 | } |
||
| 95 | |||
| 96 | $isAllowed = 'true' === $this->settingsManager->getSetting('session.allow_coach_to_edit_course_session') && $isCoachAllowedToEdit; |
||
| 97 | |||
| 98 | if ($checkStudentView) { |
||
| 99 | $isAllowed = $isAllowed && !$studentViewIsActive; |
||
| 100 | } |
||
| 101 | } elseif ($checkStudentView) { |
||
| 102 | $isAllowed = $isCourseAdmin && !$studentViewIsActive; |
||
| 103 | } else { |
||
| 104 | $isAllowed = $isCourseAdmin; |
||
| 105 | } |
||
| 106 | |||
| 107 | return $isAllowed; |
||
| 108 | } |
||
| 110 |