| Conditions | 12 |
| Paths | 768 |
| Total Lines | 74 |
| Lines | 74 |
| Ratio | 100 % |
| 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 | View Code Duplication | public static function view_bbbsession_set($context, &$session) { |
|
| 177 | |||
| 178 | global $CFG, $USER; |
||
| 179 | |||
| 180 | $session['username'] = fullname($USER); |
||
| 181 | $session['userID'] = $USER->id; |
||
| 182 | $session['administrator'] = is_siteadmin($session['userID']); |
||
| 183 | $participantlist = bigbluebuttonbn_get_participant_list($session['bigbluebuttonbn'], $context); |
||
| 184 | $session['moderator'] = bigbluebuttonbn_is_moderator($context, $participantlist); |
||
| 185 | $session['managerecordings'] = ($session['administrator'] |
||
| 186 | || has_capability('mod/bigbluebuttonbn:managerecordings', $context)); |
||
| 187 | $session['importrecordings'] = ($session['managerecordings']); |
||
| 188 | $session['modPW'] = $session['bigbluebuttonbn']->moderatorpass; |
||
| 189 | $session['viewerPW'] = $session['bigbluebuttonbn']->viewerpass; |
||
| 190 | $session['meetingid'] = $session['bigbluebuttonbn']->meetingid.'-'.$session['course']->id.'-'. |
||
| 191 | $session['bigbluebuttonbn']->id; |
||
| 192 | $session['meetingname'] = $session['bigbluebuttonbn']->name; |
||
| 193 | $session['meetingdescription'] = $session['bigbluebuttonbn']->intro; |
||
| 194 | $session['userlimit'] = intval((int) config::get('userlimit_default')); |
||
| 195 | if ((boolean) config::get('userlimit_editable')) { |
||
| 196 | $session['userlimit'] = intval($session['bigbluebuttonbn']->userlimit); |
||
| 197 | } |
||
| 198 | $session['voicebridge'] = $session['bigbluebuttonbn']->voicebridge; |
||
| 199 | if ($session['bigbluebuttonbn']->voicebridge > 0) { |
||
| 200 | $session['voicebridge'] = 70000 + $session['bigbluebuttonbn']->voicebridge; |
||
| 201 | } |
||
| 202 | $session['wait'] = $session['bigbluebuttonbn']->wait; |
||
| 203 | $session['record'] = $session['bigbluebuttonbn']->record; |
||
| 204 | |||
| 205 | $session['recordallfromstart'] = $CFG->bigbluebuttonbn_recording_all_from_start_default; |
||
| 206 | if ($CFG->bigbluebuttonbn_recording_all_from_start_editable) { |
||
| 207 | $session['recordallfromstart'] = $session['bigbluebuttonbn']->recordallfromstart; |
||
| 208 | } |
||
| 209 | |||
| 210 | $session['recordhidebutton'] = $CFG->bigbluebuttonbn_recording_hide_button_default; |
||
| 211 | if ($CFG->bigbluebuttonbn_recording_hide_button_editable) { |
||
| 212 | $session['recordhidebutton'] = $session['bigbluebuttonbn']->recordhidebutton; |
||
| 213 | } |
||
| 214 | |||
| 215 | $session['welcome'] = $session['bigbluebuttonbn']->welcome; |
||
| 216 | if (!isset($session['welcome']) || $session['welcome'] == '') { |
||
| 217 | $session['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn'); |
||
| 218 | } |
||
| 219 | if ($session['bigbluebuttonbn']->record) { |
||
| 220 | // Check if is enable record all from start. |
||
| 221 | if ($session['recordallfromstart']) { |
||
| 222 | $session['welcome'] .= '<br><br>'.get_string('bbbrecordallfromstartwarning', |
||
| 223 | 'bigbluebuttonbn'); |
||
| 224 | } else { |
||
| 225 | $session['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn'); |
||
| 226 | } |
||
| 227 | } |
||
| 228 | $session['openingtime'] = $session['bigbluebuttonbn']->openingtime; |
||
| 229 | $session['closingtime'] = $session['bigbluebuttonbn']->closingtime; |
||
| 230 | $session['muteonstart'] = $session['bigbluebuttonbn']->muteonstart; |
||
| 231 | $session['context'] = $context; |
||
| 232 | $session['origin'] = 'Moodle'; |
||
| 233 | $session['originVersion'] = $CFG->release; |
||
| 234 | $parsedurl = parse_url($CFG->wwwroot); |
||
| 235 | $session['originServerName'] = $parsedurl['host']; |
||
| 236 | $session['originServerUrl'] = $CFG->wwwroot; |
||
| 237 | $session['originServerCommonName'] = ''; |
||
| 238 | $session['originTag'] = 'moodle-mod_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')'; |
||
| 239 | $session['bnserver'] = bigbluebuttonbn_is_bn_server(); |
||
| 240 | $session['clienttype'] = config::get('clienttype_default'); |
||
| 241 | |||
| 242 | if (config::get('clienttype_editable')) { |
||
| 243 | $session['clienttype'] = $session['bigbluebuttonbn']->clienttype; |
||
| 244 | } |
||
| 245 | |||
| 246 | if (!config::clienttype_enabled()) { |
||
| 247 | $session['clienttype'] = BIGBLUEBUTTON_CLIENTTYPE_FLASH; |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 286 |
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.