| Conditions | 16 |
| Paths | 194 |
| Total Lines | 73 |
| Code Lines | 46 |
| 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 |
||
| 96 | public static function getPermissions($studentId, $currentUserId) |
||
| 97 | { |
||
| 98 | $installed = AppPlugin::getInstance()->isInstalled('studentfollowup'); |
||
| 99 | if (false === $installed) { |
||
| 100 | return [ |
||
| 101 | 'is_allow' => false, |
||
| 102 | 'show_private' => false, |
||
| 103 | ]; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($studentId === $currentUserId) { |
||
| 107 | $isAllow = true; |
||
| 108 | $showPrivate = true; |
||
| 109 | } else { |
||
| 110 | $isDrh = api_is_drh(); |
||
| 111 | $isCareTaker = false; |
||
| 112 | $isDrhRelatedViaPost = false; |
||
| 113 | $isCourseCoach = false; |
||
| 114 | $isDrhRelatedToSession = false; |
||
| 115 | |||
| 116 | // Only admins and DRH that follow the user |
||
| 117 | $isAdmin = api_is_platform_admin(); |
||
| 118 | |||
| 119 | // Check if user is care taker |
||
| 120 | if ($isDrh) { |
||
| 121 | $criteria = [ |
||
| 122 | 'user' => $studentId, |
||
| 123 | 'insertUser' => $currentUserId, |
||
| 124 | ]; |
||
| 125 | $repo = Database::getManager()->getRepository('ChamiloPluginBundle:StudentFollowUp\CarePost'); |
||
| 126 | $post = $repo->findOneBy($criteria); |
||
| 127 | if ($post) { |
||
| 128 | $isDrhRelatedViaPost = true; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | // Check if course session coach |
||
| 133 | $sessions = SessionManager::get_sessions_by_user($studentId, false, true); |
||
| 134 | if (!empty($sessions)) { |
||
| 135 | foreach ($sessions as $session) { |
||
| 136 | $sessionId = $session['session_id']; |
||
| 137 | $sessionDrhInfo = SessionManager::getSessionFollowedByDrh( |
||
| 138 | $currentUserId, |
||
| 139 | $sessionId |
||
| 140 | ); |
||
| 141 | if (!empty($sessionDrhInfo)) { |
||
| 142 | $isDrhRelatedToSession = true; |
||
| 143 | |||
| 144 | break; |
||
| 145 | } |
||
| 146 | foreach ($session['courses'] as $course) { |
||
| 147 | $coachList = SessionManager::getCoachesByCourseSession( |
||
| 148 | $sessionId, |
||
| 149 | $course['real_id'] |
||
| 150 | ); |
||
| 151 | if (!empty($coachList) && in_array($currentUserId, $coachList)) { |
||
| 152 | $isCourseCoach = true; |
||
| 153 | |||
| 154 | break 2; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | $isCareTaker = $isDrhRelatedViaPost && $isDrhRelatedToSession; |
||
| 161 | |||
| 162 | $isAllow = $isAdmin || $isCareTaker || $isDrhRelatedToSession || $isCourseCoach; |
||
| 163 | $showPrivate = $isAdmin || $isCareTaker; |
||
| 164 | } |
||
| 165 | |||
| 166 | return [ |
||
| 167 | 'is_allow' => $isAllow, |
||
| 168 | 'show_private' => $showPrivate, |
||
| 169 | ]; |
||
| 256 |