| Conditions | 20 |
| Paths | 12672 |
| Total Lines | 118 |
| Code Lines | 90 |
| 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 |
||
| 54 | function get_users($from, $limit, $column, $direction) |
||
|
|
|||
| 55 | { |
||
| 56 | $active = isset($_GET['active']) ? $_GET['active'] : 1; |
||
| 57 | $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null; |
||
| 58 | $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null; |
||
| 59 | $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null; |
||
| 60 | $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0; |
||
| 61 | |||
| 62 | $lastConnectionDate = null; |
||
| 63 | if (!empty($sleepingDays)) { |
||
| 64 | $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago')); |
||
| 65 | } |
||
| 66 | |||
| 67 | $is_western_name_order = api_is_western_name_order(); |
||
| 68 | $coach_id = api_get_user_id(); |
||
| 69 | $column = 'u.user_id'; |
||
| 70 | $drhLoaded = false; |
||
| 71 | if (api_is_drh()) { |
||
| 72 | if (api_drh_can_access_all_session_content()) { |
||
| 73 | $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus( |
||
| 74 | 'drh_all', |
||
| 75 | api_get_user_id(), |
||
| 76 | false, |
||
| 77 | $from, |
||
| 78 | $limit, |
||
| 79 | '', |
||
| 80 | $direction, |
||
| 81 | $keyword, |
||
| 82 | $active, |
||
| 83 | $lastConnectionDate, |
||
| 84 | null, |
||
| 85 | null, |
||
| 86 | $status |
||
| 87 | ); |
||
| 88 | $drhLoaded = true; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($drhLoaded === false) { |
||
| 93 | $students = UserManager::getUsersFollowedByUser( |
||
| 94 | api_get_user_id(), |
||
| 95 | $status, |
||
| 96 | false, |
||
| 97 | false, |
||
| 98 | false, |
||
| 99 | $from, |
||
| 100 | $limit, |
||
| 101 | '', |
||
| 102 | $direction, |
||
| 103 | $active, |
||
| 104 | $lastConnectionDate, |
||
| 105 | COURSEMANAGER, |
||
| 106 | $keyword |
||
| 107 | ); |
||
| 108 | } |
||
| 109 | |||
| 110 | $all_datas = array(); |
||
| 111 | |||
| 112 | foreach ($students as $student_data) { |
||
| 113 | $student_id = $student_data['user_id']; |
||
| 114 | if (isset($_GET['id_session'])) { |
||
| 115 | $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']); |
||
| 116 | } |
||
| 117 | |||
| 118 | $avg_time_spent = $avg_student_score = $avg_student_progress = 0; |
||
| 119 | $nb_courses_student = 0; |
||
| 120 | if (!empty($courses)) { |
||
| 121 | foreach ($courses as $course_code) { |
||
| 122 | $courseInfo = api_get_course_info($course_code); |
||
| 123 | $courseId = $courseInfo['real_id']; |
||
| 124 | |||
| 125 | if (CourseManager::is_user_subscribed_in_course($student_id, $course_code, true)) { |
||
| 126 | $avg_time_spent += Tracking::get_time_spent_on_the_course($student_id, $courseId, $_GET['id_session']); |
||
| 127 | $my_average = Tracking::get_avg_student_score($student_id, $course_code); |
||
| 128 | if (is_numeric($my_average)) { |
||
| 129 | $avg_student_score += $my_average; |
||
| 130 | } |
||
| 131 | $avg_student_progress += Tracking::get_avg_student_progress($student_id, $course_code); |
||
| 132 | $nb_courses_student++; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($nb_courses_student > 0) { |
||
| 138 | $avg_time_spent = $avg_time_spent / $nb_courses_student; |
||
| 139 | $avg_student_score = $avg_student_score / $nb_courses_student; |
||
| 140 | $avg_student_progress = $avg_student_progress / $nb_courses_student; |
||
| 141 | } else { |
||
| 142 | $avg_time_spent = null; |
||
| 143 | $avg_student_score = null; |
||
| 144 | $avg_student_progress = null; |
||
| 145 | } |
||
| 146 | |||
| 147 | $row = array(); |
||
| 148 | if ($is_western_name_order) { |
||
| 149 | $row[] = $student_data['firstname']; |
||
| 150 | $row[] = $student_data['lastname']; |
||
| 151 | } else { |
||
| 152 | $row[] = $student_data['lastname']; |
||
| 153 | $row[] = $student_data['firstname']; |
||
| 154 | } |
||
| 155 | $string_date = Tracking::get_last_connection_date($student_id, true); |
||
| 156 | $first_date = Tracking::get_first_connection_date($student_id); |
||
| 157 | $row[] = $first_date; |
||
| 158 | $row[] = $string_date; |
||
| 159 | |||
| 160 | if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) { |
||
| 161 | $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$sessionId.'"> |
||
| 162 | '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a>'; |
||
| 163 | } else { |
||
| 164 | $detailsLink = '<a href="myStudents.php?student='.$student_id.'"> |
||
| 165 | '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a>'; |
||
| 166 | } |
||
| 167 | $row[] = $detailsLink; |
||
| 168 | $all_datas[] = $row; |
||
| 169 | } |
||
| 170 | |||
| 171 | return $all_datas; |
||
| 172 | } |
||
| 302 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.