| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Code Lines | 37 |
| 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 |
||
| 16 | function get_course_usage($course_code, $session_id = 0) |
||
| 17 | { |
||
| 18 | $table = Database::get_main_table(TABLE_MAIN_COURSE); |
||
| 19 | $course_code = Database::escape_string($course_code); |
||
| 20 | $sql = "SELECT * FROM $table WHERE code='".$course_code."'"; |
||
| 21 | $res = Database::query($sql); |
||
| 22 | $course = Database::fetch_object($res); |
||
| 23 | // Learnpaths |
||
| 24 | $table = Database :: get_course_table(TABLE_LP_MAIN); |
||
| 25 | $usage[] = array( |
||
| 26 | get_lang(ucfirst(TOOL_LEARNPATH)), |
||
| 27 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
|
|
|||
| 28 | ); |
||
| 29 | // Forums |
||
| 30 | $table = Database :: get_course_table(TABLE_FORUM); |
||
| 31 | $usage[] = array(get_lang('Forums'), CourseManager::count_rows_course_table($table, $session_id, $course->id)); |
||
| 32 | // Quizzes |
||
| 33 | $table = Database :: get_course_table(TABLE_QUIZ_TEST); |
||
| 34 | $usage[] = array( |
||
| 35 | get_lang(ucfirst(TOOL_QUIZ)), |
||
| 36 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
| 37 | ); |
||
| 38 | // Documents |
||
| 39 | $table = Database :: get_course_table(TABLE_DOCUMENT); |
||
| 40 | $usage[] = array( |
||
| 41 | get_lang(ucfirst(TOOL_DOCUMENT)), |
||
| 42 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
| 43 | ); |
||
| 44 | // Groups |
||
| 45 | $table = Database :: get_course_table(TABLE_GROUP); |
||
| 46 | $usage[] = array( |
||
| 47 | get_lang(ucfirst(TOOL_GROUP)), |
||
| 48 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
| 49 | ); |
||
| 50 | // Calendar |
||
| 51 | $table = Database :: get_course_table(TABLE_AGENDA); |
||
| 52 | $usage[] = array( |
||
| 53 | get_lang(ucfirst(TOOL_CALENDAR_EVENT)), |
||
| 54 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
| 55 | ); |
||
| 56 | // Link |
||
| 57 | $table = Database::get_course_table(TABLE_LINK); |
||
| 58 | $usage[] = array( |
||
| 59 | get_lang(ucfirst(TOOL_LINK)), |
||
| 60 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
| 61 | ); |
||
| 62 | // Announcements |
||
| 63 | $table = Database::get_course_table(TABLE_ANNOUNCEMENT); |
||
| 64 | $usage[] = array( |
||
| 65 | get_lang(ucfirst(TOOL_ANNOUNCEMENT)), |
||
| 66 | CourseManager::count_rows_course_table($table, $session_id, $course->id) |
||
| 67 | ); |
||
| 68 | return $usage; |
||
| 69 | } |
||
| 70 | |||
| 174 |
This method has been deprecated.