| Conditions | 19 |
| Paths | 35 |
| Total Lines | 101 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 133 | function displayBigBlueButtonRooms($endpoint, $shared_secret, $moderator, $course, $bigbluebuttonbn, $groupObj = null ){ |
||
| 134 | $joinURL = null; |
||
| 135 | $group = "-"; |
||
| 136 | $users = "-"; |
||
| 137 | $running = "-"; |
||
| 138 | $actions = "-"; |
||
| 139 | $viewerList = "-"; |
||
| 140 | $moderatorList = "-"; |
||
| 141 | $recording = "-"; |
||
| 142 | |||
| 143 | if ( !$bigbluebuttonbn->visible ) { |
||
| 144 | // Nothing to do |
||
| 145 | } else { |
||
| 146 | $modPW = $bigbluebuttonbn->moderatorpass; |
||
| 147 | $attPW = $bigbluebuttonbn->viewerpass; |
||
| 148 | |||
| 149 | $meetingID = $bigbluebuttonbn->meetingid.'-'.$course->id.'-'.$bigbluebuttonbn->id; |
||
| 150 | // |
||
| 151 | // Output Users in the meeting |
||
| 152 | // |
||
| 153 | if( $groupObj == null ){ |
||
| 154 | $meetingInfo = bigbluebuttonbn_getMeetingInfoArray( $meetingID, $modPW, $endpoint, $shared_secret ); |
||
| 155 | $joinURL = '<a href="view.php?id='.$bigbluebuttonbn->coursemodule.'">'.format_string($bigbluebuttonbn->name).'</a>'; |
||
| 156 | } else { |
||
| 157 | $meetingInfo = bigbluebuttonbn_getMeetingInfoArray( $meetingID.'['.$groupObj->id.']', $modPW, $endpoint, $shared_secret ); |
||
| 158 | $joinURL = '<a href="view.php?id='.$bigbluebuttonbn->coursemodule.'&group='.$groupObj->id.'">'.format_string($bigbluebuttonbn->name).'</a>'; |
||
| 159 | $group = $groupObj->name; |
||
| 160 | } |
||
| 161 | |||
| 162 | if (!$meetingInfo) { |
||
| 163 | // |
||
| 164 | // The server was unreachable |
||
| 165 | // |
||
| 166 | print_error( get_string( 'index_error_unable_display', 'bigbluebuttonbn' )); |
||
| 167 | return; |
||
| 168 | } |
||
| 169 | |||
| 170 | if (isset($meetingInfo['messageKey'])) { |
||
| 171 | // |
||
| 172 | // There was an error returned |
||
| 173 | // |
||
| 174 | if ($meetingInfo['messageKey'] == "checksumError") { |
||
| 175 | print_error( get_string( 'index_error_checksum', 'bigbluebuttonbn' )); |
||
| 176 | return; |
||
| 177 | } |
||
| 178 | |||
| 179 | if ($meetingInfo['messageKey'] == "notFound" || $meetingInfo['messageKey'] == "invalidMeetingId") { |
||
| 180 | // |
||
| 181 | // The meeting does not exist yet on the BigBlueButton server. This is OK. |
||
| 182 | // |
||
| 183 | } else { |
||
| 184 | // |
||
| 185 | // There was an error |
||
| 186 | // |
||
| 187 | $users = $meetingInfo['messageKey'].": ".$meetingInfo['message']; |
||
| 188 | } |
||
| 189 | } else { |
||
| 190 | // |
||
| 191 | // The meeting info was returned |
||
| 192 | // |
||
| 193 | if ($meetingInfo['running'] == 'true') { |
||
| 194 | if ( $moderator ) { |
||
| 195 | if( $groupObj == null ) { |
||
| 196 | $actions = '<form name="form1" method="post" action=""><INPUT type="hidden" name="id" value="'.$course->id.'"><INPUT type="hidden" name="a" value="'.$bigbluebuttonbn->id.'"><INPUT type="submit" name="submit" value="end" onclick="return confirm(\''. get_string('index_confirm_end', 'bigbluebuttonbn' ).'\')"></form>'; |
||
| 197 | } else { |
||
| 198 | $actions = '<form name="form1" method="post" action=""><INPUT type="hidden" name="id" value="'.$course->id.'"><INPUT type="hidden" name="a" value="'.$bigbluebuttonbn->id.'"><INPUT type="hidden" name="g" value="'.$groupObj->id.'"><INPUT type="submit" name="submit" value="end" onclick="return confirm(\''. get_string('index_confirm_end', 'bigbluebuttonbn' ).'\')"></form>'; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | if ( isset($meetingInfo['recording']) && $meetingInfo['recording'] == 'true' ){ // if it has been set when meeting created, set the variable on/off |
||
| 202 | $recording = get_string('index_enabled', 'bigbluebuttonbn' ); |
||
| 203 | } |
||
| 204 | |||
| 205 | $xml = $meetingInfo['attendees']; |
||
| 206 | if (count( $xml ) && count( $xml->attendee ) ) { |
||
| 207 | $users = count( $xml->attendee ); |
||
| 208 | $viewer_count = 0; |
||
| 209 | $moderator_count = 0; |
||
| 210 | foreach ( $xml->attendee as $attendee ) { |
||
| 211 | if ($attendee->role == "MODERATOR" ) { |
||
| 212 | if ( $viewer_count++ > 0 ) { |
||
| 213 | $moderatorList .= ", "; |
||
| 214 | } else { |
||
| 215 | $moderatorList = ""; |
||
| 216 | } |
||
| 217 | $moderatorList .= $attendee->fullName; |
||
| 218 | } else { |
||
| 219 | if ( $moderator_count++ > 0 ) { |
||
| 220 | $viewerList .= ", "; |
||
| 221 | } else { |
||
| 222 | $viewerList = ""; |
||
| 223 | } |
||
| 224 | $viewerList .= $attendee->fullName; |
||
| 225 | } |
||
| 226 | } |
||
| 227 | } |
||
| 228 | } |
||
| 229 | } |
||
| 230 | |||
| 231 | return array ($bigbluebuttonbn->section, $joinURL, $group, $users, $viewerList, $moderatorList, $recording, $actions ); |
||
| 232 | } |
||
| 233 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.