Conditions | 9 |
Paths | 5 |
Total Lines | 51 |
Code Lines | 35 |
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 |
||
173 | public static function getUsers($status, $currentUserId, $sessionId, $start, $limit) |
||
174 | { |
||
175 | $sessions = []; |
||
176 | $courses = []; |
||
177 | $sessionsFull = []; |
||
178 | |||
179 | switch ($status) { |
||
180 | case COURSEMANAGER: |
||
181 | $sessionsFull = SessionManager::getSessionsCoachedByUser($currentUserId); |
||
182 | $sessions = array_column($sessionsFull, 'id'); |
||
183 | if (!empty($sessionId)) { |
||
184 | $sessions = [$sessionId]; |
||
185 | } |
||
186 | // Get session courses where I'm coach |
||
187 | $courseList = SessionManager::getCoursesListByCourseCoach($currentUserId); |
||
188 | $courses = []; |
||
189 | /** @var SessionRelCourseRelUser $courseItem */ |
||
190 | foreach ($courseList as $courseItem) { |
||
191 | $courses[] = $courseItem->getCourse()->getId(); |
||
192 | } |
||
193 | break; |
||
194 | case DRH: |
||
195 | $sessionsFull = SessionManager::get_sessions_followed_by_drh($currentUserId); |
||
196 | $sessions = array_column($sessionsFull, 'id'); |
||
197 | |||
198 | if (!empty($sessionId)) { |
||
199 | $sessions = [$sessionId]; |
||
200 | } |
||
201 | $courses = []; |
||
202 | foreach ($sessions as $sessionId) { |
||
|
|||
203 | $sessionDrhInfo = SessionManager::getSessionFollowedByDrh( |
||
204 | $currentUserId, |
||
205 | $sessionId |
||
206 | ); |
||
207 | if ($sessionDrhInfo && isset($sessionDrhInfo['course_list'])) { |
||
208 | $courses = array_merge($courses, array_column($sessionDrhInfo['course_list'], 'id')); |
||
209 | } |
||
210 | } |
||
211 | break; |
||
212 | } |
||
213 | |||
214 | $userList = SessionManager::getUsersByCourseAndSessionList( |
||
215 | $sessions, |
||
216 | $courses, |
||
217 | $start, |
||
218 | $limit |
||
219 | ); |
||
220 | |||
221 | return [ |
||
222 | 'users' => $userList, |
||
223 | 'sessions' => $sessionsFull, |
||
224 | ]; |
||
246 |