| Conditions | 9 |
| Paths | 128 |
| Total Lines | 63 |
| Lines | 63 |
| 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 |
||
| 46 | View Code Duplication | public static function bigbluebuttonbn_view_bbbsession_set($context, &$bbbsession) { |
|
|
|
|||
| 47 | |||
| 48 | global $CFG, $USER; |
||
| 49 | // User data. |
||
| 50 | $bbbsession['username'] = fullname($USER); |
||
| 51 | $bbbsession['userID'] = $USER->id; |
||
| 52 | // User roles. |
||
| 53 | $bbbsession['administrator'] = is_siteadmin($bbbsession['userID']); |
||
| 54 | $participantlist = bigbluebuttonbn_get_participant_list($bbbsession['bigbluebuttonbn'], $context); |
||
| 55 | $bbbsession['moderator'] = bigbluebuttonbn_is_moderator($context, $participantlist); |
||
| 56 | $bbbsession['managerecordings'] = ($bbbsession['administrator'] |
||
| 57 | || has_capability('mod/bigbluebuttonbn:managerecordings', $context)); |
||
| 58 | $bbbsession['importrecordings'] = ($bbbsession['managerecordings']); |
||
| 59 | // Server data. |
||
| 60 | $bbbsession['modPW'] = $bbbsession['bigbluebuttonbn']->moderatorpass; |
||
| 61 | $bbbsession['viewerPW'] = $bbbsession['bigbluebuttonbn']->viewerpass; |
||
| 62 | // Database info related to the activity. |
||
| 63 | $bbbsession['meetingid'] = $bbbsession['bigbluebuttonbn']->meetingid.'-'.$bbbsession['course']->id.'-'. |
||
| 64 | $bbbsession['bigbluebuttonbn']->id; |
||
| 65 | $bbbsession['meetingname'] = $bbbsession['bigbluebuttonbn']->name; |
||
| 66 | $bbbsession['meetingdescription'] = $bbbsession['bigbluebuttonbn']->intro; |
||
| 67 | // Extra data for setting up the Meeting. |
||
| 68 | $bbbsession['userlimit'] = intval((int)\mod_bigbluebuttonbn\locallib\config::get('userlimit_default')); |
||
| 69 | if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('userlimit_editable')) { |
||
| 70 | $bbbsession['userlimit'] = intval($bbbsession['bigbluebuttonbn']->userlimit); |
||
| 71 | } |
||
| 72 | $bbbsession['voicebridge'] = $bbbsession['bigbluebuttonbn']->voicebridge; |
||
| 73 | if ($bbbsession['bigbluebuttonbn']->voicebridge > 0) { |
||
| 74 | $bbbsession['voicebridge'] = 70000 + $bbbsession['bigbluebuttonbn']->voicebridge; |
||
| 75 | } |
||
| 76 | $bbbsession['wait'] = $bbbsession['bigbluebuttonbn']->wait; |
||
| 77 | $bbbsession['record'] = $bbbsession['bigbluebuttonbn']->record; |
||
| 78 | $bbbsession['welcome'] = $bbbsession['bigbluebuttonbn']->welcome; |
||
| 79 | if (!isset($bbbsession['welcome']) || $bbbsession['welcome'] == '') { |
||
| 80 | $bbbsession['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn'); |
||
| 81 | } |
||
| 82 | if ($bbbsession['bigbluebuttonbn']->record) { |
||
| 83 | $bbbsession['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn'); |
||
| 84 | } |
||
| 85 | $bbbsession['openingtime'] = $bbbsession['bigbluebuttonbn']->openingtime; |
||
| 86 | $bbbsession['closingtime'] = $bbbsession['bigbluebuttonbn']->closingtime; |
||
| 87 | // Additional info related to the course. |
||
| 88 | $bbbsession['context'] = $context; |
||
| 89 | // Metadata (origin). |
||
| 90 | $bbbsession['origin'] = 'Moodle'; |
||
| 91 | $bbbsession['originVersion'] = $CFG->release; |
||
| 92 | $parsedurl = parse_url($CFG->wwwroot); |
||
| 93 | $bbbsession['originServerName'] = $parsedurl['host']; |
||
| 94 | $bbbsession['originServerUrl'] = $CFG->wwwroot; |
||
| 95 | $bbbsession['originServerCommonName'] = ''; |
||
| 96 | $bbbsession['originTag'] = 'moodle-mod_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')'; |
||
| 97 | $bbbsession['bnserver'] = bigbluebuttonbn_is_bn_server(); |
||
| 98 | // Setting for clienttype, assign flash if not enabled, or default if not editable. |
||
| 99 | $bbbsession['clienttype'] = \mod_bigbluebuttonbn\locallib\config::get('clienttype_default'); |
||
| 100 | if (\mod_bigbluebuttonbn\locallib\config::get('clienttype_editable')) { |
||
| 101 | $bbbsession['clienttype'] = $bbbsession['bigbluebuttonbn']->clienttype; |
||
| 102 | } |
||
| 103 | if (!\mod_bigbluebuttonbn\locallib\config::clienttype_enabled()) { |
||
| 104 | $bbbsession['clienttype'] = BIGBLUEBUTTON_CLIENTTYPE_FLASH; |
||
| 105 | } |
||
| 106 | |||
| 107 | return($bbbsession); |
||
| 108 | } |
||
| 109 | |||
| 245 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.