| Conditions | 6 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 41 |
| 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 |
||
| 82 | public function getContent() |
||
| 83 | { |
||
| 84 | $content = ''; |
||
| 85 | $sessions = $this->sessions; |
||
| 86 | if (count($sessions) > 0) { |
||
| 87 | $sessions_table = '<table class="data_table" width:"95%">'; |
||
| 88 | $sessions_table .= '<tr> |
||
| 89 | <th >'.get_lang('Title').'</th> |
||
| 90 | <th >'.get_lang('Date').'</th> |
||
| 91 | <th width="100px">'.get_lang('NbCoursesPerSession').'</th> |
||
| 92 | </tr>'; |
||
| 93 | $i = 1; |
||
| 94 | foreach ($sessions as $session) { |
||
| 95 | $session_id = intval($session['id']); |
||
| 96 | $title = $session['name']; |
||
| 97 | |||
| 98 | if (!empty($session['access_start_date'])) { |
||
| 99 | $dateFrom = api_convert_and_format_date( |
||
| 100 | $session['access_start_date'], |
||
| 101 | DATE_FORMAT_SHORT, |
||
| 102 | date_default_timezone_get() |
||
| 103 | ); |
||
| 104 | $dateUntil = api_convert_and_format_date( |
||
| 105 | $session['access_end_date'], |
||
| 106 | DATE_FORMAT_SHORT, |
||
| 107 | date_default_timezone_get() |
||
| 108 | ); |
||
| 109 | |||
| 110 | $date = vsprintf(get_lang('FromDateXToDateY'), [$dateFrom, $dateUntil]); |
||
| 111 | } else { |
||
| 112 | $date = ' - '; |
||
| 113 | } |
||
| 114 | |||
| 115 | $count_courses_in_session = count(Tracking::get_courses_list_from_session($session_id)); |
||
| 116 | |||
| 117 | if ($i % 2 == 0) { |
||
| 118 | $class_tr = 'row_odd'; |
||
| 119 | } else { |
||
| 120 | $class_tr = 'row_even'; |
||
| 121 | } |
||
| 122 | |||
| 123 | $sessions_table .= '<tr class="'.$class_tr.'"> |
||
| 124 | <td>'.$title.'</td> |
||
| 125 | <td align="center">'.$date.'</td> |
||
| 126 | <td align="center">'.$count_courses_in_session.'</td> |
||
| 127 | </tr>'; |
||
| 128 | $i++; |
||
| 129 | } |
||
| 130 | $sessions_table .= '</table>'; |
||
| 131 | $content .= $sessions_table; |
||
| 132 | } else { |
||
| 133 | $content .= get_lang('ThereIsNoInformationAboutYourSessions'); |
||
| 134 | } |
||
| 135 | |||
| 136 | if (count($sessions) > 0) { |
||
| 137 | $content .= '<div style="text-align:right;margin-top:10px;"><a href="'.api_get_path(WEB_CODE_PATH).'mySpace/session.php">'.get_lang('SeeMore').'</a></div>'; |
||
| 138 | } |
||
| 139 | |||
| 140 | return $content; |
||
| 141 | } |
||
| 153 |