| Conditions | 12 | 
| Paths | 768 | 
| Total Lines | 82 | 
| 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 | ||
| 176 |     public static function view_bbbsession_set($context, &$bbbsession) { | ||
| 177 | |||
| 178 | global $CFG, $USER; | ||
| 179 | |||
| 180 | $bbbsession['username'] = fullname($USER); | ||
| 181 | $bbbsession['userID'] = $USER->id; | ||
| 182 | $bbbsession['administrator'] = is_siteadmin($bbbsession['userID']); | ||
| 183 | $participantlist = bigbluebuttonbn_get_participant_list($bbbsession['bigbluebuttonbn'], $context); | ||
| 184 | $bbbsession['moderator'] = bigbluebuttonbn_is_moderator($context, $participantlist); | ||
| 185 | $bbbsession['managerecordings'] = ($bbbsession['administrator'] | ||
| 186 |             || has_capability('mod/bigbluebuttonbn:managerecordings', $context)); | ||
| 187 | $bbbsession['importrecordings'] = ($bbbsession['managerecordings']); | ||
| 188 | $bbbsession['modPW'] = $bbbsession['bigbluebuttonbn']->moderatorpass; | ||
| 189 | $bbbsession['viewerPW'] = $bbbsession['bigbluebuttonbn']->viewerpass; | ||
| 190 | $bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid.'-'.$bbbsession['course']->id.'-'. | ||
| 191 | $bbbsession['bigbluebuttonbn']->id; | ||
| 192 | $bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name; | ||
| 193 | $bbbsession['meetingdescription'] = $bbbsession['bigbluebuttonbn']->intro; | ||
| 194 |         $bbbsession['userlimit'] = intval((int) config::get('userlimit_default')); | ||
| 195 |         if ((boolean) config::get('userlimit_editable')) { | ||
| 196 | $bbbsession['userlimit'] = intval($bbbsession['bigbluebuttonbn']->userlimit); | ||
| 197 | } | ||
| 198 | $bbbsession['voicebridge'] = $bbbsession['bigbluebuttonbn']->voicebridge; | ||
| 199 |         if ($bbbsession['bigbluebuttonbn']->voicebridge > 0) { | ||
| 200 | $bbbsession['voicebridge'] = 70000 + $bbbsession['bigbluebuttonbn']->voicebridge; | ||
| 201 | } | ||
| 202 | $bbbsession['wait'] = $bbbsession['bigbluebuttonbn']->wait; | ||
| 203 | $bbbsession['record'] = $bbbsession['bigbluebuttonbn']->record; | ||
| 204 | $bbbsession['recordallfromstart'] = $CFG->bigbluebuttonbn_recording_all_from_start_default; | ||
| 205 |         if ($CFG->bigbluebuttonbn_recording_all_from_start_editable) { | ||
| 206 | $bbbsession['recordallfromstart'] = $bbbsession['bigbluebuttonbn']->recordallfromstart; | ||
| 207 | } | ||
| 208 | $bbbsession['recordhidebutton'] = $CFG->bigbluebuttonbn_recording_hide_button_default; | ||
| 209 |         if ($CFG->bigbluebuttonbn_recording_hide_button_editable) { | ||
| 210 | $bbbsession['recordhidebutton'] = $bbbsession['bigbluebuttonbn']->recordhidebutton; | ||
| 211 | } | ||
| 212 | $bbbsession['welcome'] = $bbbsession['bigbluebuttonbn']->welcome; | ||
| 213 |         if (!isset($bbbsession['welcome']) || $bbbsession['welcome'] == '') { | ||
| 214 |             $bbbsession['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn'); | ||
| 215 | } | ||
| 216 |         if ($bbbsession['bigbluebuttonbn']->record) { | ||
| 217 | // Check if is enable record all from start. | ||
| 218 |             if ($bbbsession['recordallfromstart']) { | ||
| 219 |                 $bbbsession['welcome'] .= '<br><br>'.get_string('bbbrecordallfromstartwarning', | ||
| 220 | 'bigbluebuttonbn'); | ||
| 221 |             } else { | ||
| 222 |                 $bbbsession['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn'); | ||
| 223 | } | ||
| 224 | } | ||
| 225 | $bbbsession['openingtime'] = $bbbsession['bigbluebuttonbn']->openingtime; | ||
| 226 | $bbbsession['closingtime'] = $bbbsession['bigbluebuttonbn']->closingtime; | ||
| 227 | $bbbsession['muteonstart'] = $bbbsession['bigbluebuttonbn']->muteonstart; | ||
| 228 | // Lock settings. | ||
| 229 | $bbbsession['disablecam'] = $bbbsession['bigbluebuttonbn']->disablecam; | ||
| 230 | $bbbsession['disablemic'] = $bbbsession['bigbluebuttonbn']->disablemic; | ||
| 231 | $bbbsession['disableprivatechat'] = $bbbsession['bigbluebuttonbn']->disableprivatechat; | ||
| 232 | $bbbsession['disablepublicchat'] = $bbbsession['bigbluebuttonbn']->disablepublicchat; | ||
| 233 | $bbbsession['disablenote'] = $bbbsession['bigbluebuttonbn']->disablenote; | ||
| 234 | $bbbsession['hideuserlist'] = $bbbsession['bigbluebuttonbn']->hideuserlist; | ||
| 235 | $bbbsession['lockedlayout'] = $bbbsession['bigbluebuttonbn']->lockedlayout; | ||
| 236 | $bbbsession['lockonjoin'] = $bbbsession['bigbluebuttonbn']->lockonjoin; | ||
| 237 | $bbbsession['lockonjoinconfigurable'] = $bbbsession['bigbluebuttonbn']->lockonjoinconfigurable; | ||
| 238 | // Additional info related to the course. | ||
| 239 | $bbbsession['context'] = $context; | ||
| 240 | // Metadata (origin). | ||
| 241 | $bbbsession['origin'] = 'Moodle'; | ||
| 242 | $bbbsession['originVersion'] = $CFG->release; | ||
| 243 | $parsedurl = parse_url($CFG->wwwroot); | ||
| 244 | $bbbsession['originServerName'] = $parsedurl['host']; | ||
| 245 | $bbbsession['originServerUrl'] = $CFG->wwwroot; | ||
| 246 | $bbbsession['originServerCommonName'] = ''; | ||
| 247 |         $bbbsession['originTag'] = 'moodle-mod_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')'; | ||
| 248 | $bbbsession['bnserver'] = bigbluebuttonbn_is_bn_server(); | ||
| 249 | // Setting for clienttype, assign flash if not enabled, or default if not editable. | ||
| 250 |         $bbbsession['clienttype'] = config::get('clienttype_default'); | ||
| 251 |         if (config::get('clienttype_editable')) { | ||
| 252 | $bbbsession['clienttype'] = $bbbsession['bigbluebuttonbn']->clienttype; | ||
| 253 | } | ||
| 254 |         if (!config::clienttype_enabled()) { | ||
| 255 | $bbbsession['clienttype'] = BIGBLUEBUTTON_CLIENTTYPE_FLASH; | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 294 | 
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.