Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
37 | class mobileview { |
||
38 | |||
39 | /** |
||
40 | * Return standard array with configurations required for BBB server. |
||
41 | * @param context $context |
||
42 | * @param array $session |
||
43 | * @return mixed |
||
44 | * @throws \coding_exception |
||
45 | * @throws \dml_exception |
||
46 | */ |
||
47 | View Code Duplication | public static function bbbsession_set($context, &$session) { |
|
|
|||
48 | |||
49 | global $CFG, $USER; |
||
50 | |||
51 | $session['username'] = fullname($USER); |
||
52 | $session['userID'] = $USER->id; |
||
53 | $session['administrator'] = is_siteadmin($session['userID']); |
||
54 | $participantlist = bigbluebuttonbn_get_participant_list($session['bigbluebuttonbn'], $context); |
||
55 | $session['moderator'] = bigbluebuttonbn_is_moderator($context, $participantlist); |
||
56 | $session['managerecordings'] = ($session['administrator'] |
||
57 | || has_capability('mod/bigbluebuttonbn:managerecordings', $context)); |
||
58 | $session['importrecordings'] = ($session['managerecordings']); |
||
59 | $session['modPW'] = $session['bigbluebuttonbn']->moderatorpass; |
||
60 | $session['viewerPW'] = $session['bigbluebuttonbn']->viewerpass; |
||
61 | $session['meetingid'] = $session['bigbluebuttonbn']->meetingid.'-'.$session['course']->id.'-'. |
||
62 | $session['bigbluebuttonbn']->id; |
||
63 | $session['meetingname'] = $session['bigbluebuttonbn']->name; |
||
64 | $session['meetingdescription'] = $session['bigbluebuttonbn']->intro; |
||
65 | $session['userlimit'] = intval((int)\mod_bigbluebuttonbn\locallib\config::get('userlimit_default')); |
||
66 | if ((boolean)\mod_bigbluebuttonbn\locallib\config::get('userlimit_editable')) { |
||
67 | $session['userlimit'] = intval($session['bigbluebuttonbn']->userlimit); |
||
68 | } |
||
69 | $session['voicebridge'] = $session['bigbluebuttonbn']->voicebridge; |
||
70 | if ($session['bigbluebuttonbn']->voicebridge > 0) { |
||
71 | $session['voicebridge'] = 70000 + $session['bigbluebuttonbn']->voicebridge; |
||
72 | } |
||
73 | $session['wait'] = $session['bigbluebuttonbn']->wait; |
||
74 | $session['record'] = $session['bigbluebuttonbn']->record; |
||
75 | |||
76 | $session['recordallfromstart'] = $CFG->bigbluebuttonbn_recording_all_from_start_default; |
||
77 | if ($CFG->bigbluebuttonbn_recording_all_from_start_editable) { |
||
78 | $session['recordallfromstart'] = $session['bigbluebuttonbn']->recordallfromstart; |
||
79 | } |
||
80 | |||
81 | $session['recordhidebutton'] = $CFG->bigbluebuttonbn_recording_hide_button_default; |
||
82 | if ($CFG->bigbluebuttonbn_recording_hide_button_editable) { |
||
83 | $session['recordhidebutton'] = $session['bigbluebuttonbn']->recordhidebutton; |
||
84 | } |
||
85 | |||
86 | $session['welcome'] = $session['bigbluebuttonbn']->welcome; |
||
87 | if (!isset($session['welcome']) || $session['welcome'] == '') { |
||
88 | $session['welcome'] = get_string('mod_form_field_welcome_default', 'bigbluebuttonbn'); |
||
89 | } |
||
90 | if ($session['bigbluebuttonbn']->record) { |
||
91 | // Check if is enable record all from start. |
||
92 | if ($session['recordallfromstart']) { |
||
93 | $session['welcome'] .= '<br><br>'.get_string('bbbrecordallfromstartwarning', |
||
94 | 'bigbluebuttonbn'); |
||
95 | } else { |
||
96 | $session['welcome'] .= '<br><br>'.get_string('bbbrecordwarning', 'bigbluebuttonbn'); |
||
97 | } |
||
98 | } |
||
99 | $session['openingtime'] = $session['bigbluebuttonbn']->openingtime; |
||
100 | $session['closingtime'] = $session['bigbluebuttonbn']->closingtime; |
||
101 | $session['muteonstart'] = $session['bigbluebuttonbn']->muteonstart; |
||
102 | $session['context'] = $context; |
||
103 | $session['origin'] = 'Moodle'; |
||
104 | $session['originVersion'] = $CFG->release; |
||
105 | $parsedurl = parse_url($CFG->wwwroot); |
||
106 | $session['originServerName'] = $parsedurl['host']; |
||
107 | $session['originServerUrl'] = $CFG->wwwroot; |
||
108 | $session['originServerCommonName'] = ''; |
||
109 | $session['originTag'] = 'moodle-mod_bigbluebuttonbn ('.get_config('mod_bigbluebuttonbn', 'version').')'; |
||
110 | $session['bnserver'] = bigbluebuttonbn_is_bn_server(); |
||
111 | $session['clienttype'] = \mod_bigbluebuttonbn\locallib\config::get('clienttype_default'); |
||
112 | |||
113 | if (\mod_bigbluebuttonbn\locallib\config::get('clienttype_editable')) { |
||
114 | $session['clienttype'] = $session['bigbluebuttonbn']->clienttype; |
||
115 | } |
||
116 | |||
117 | if (!\mod_bigbluebuttonbn\locallib\config::clienttype_enabled()) { |
||
118 | $session['clienttype'] = BIGBLUEBUTTON_CLIENTTYPE_FLASH; |
||
119 | } |
||
120 | |||
121 | return($session); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Build url for join to session. |
||
126 | * This method is similar to "join_meeting()" in bbb_view. |
||
127 | * @param array $bbbsession |
||
128 | * @return string |
||
129 | */ |
||
130 | public static function build_url_join_session(&$bbbsession) { |
||
140 | |||
141 | /** |
||
142 | * Return the status of an activity [open|not_started|ended]. |
||
143 | * |
||
144 | * @param array $bbbsession |
||
145 | * @return string |
||
146 | */ |
||
147 | View Code Duplication | public static function get_activity_status(&$bbbsession) { |
|
160 | |||
161 | /** |
||
162 | * Helper for preparing metadata used while creating the meeting. |
||
163 | * |
||
164 | * @param array $bbbsession |
||
165 | * @return array |
||
166 | */ |
||
167 | public static function create_meeting_metadata(&$bbbsession) { |
||
170 | |||
171 | /** |
||
172 | * Helper to prepare data used for create meeting. |
||
173 | * @param array $bbbsession |
||
174 | * @return array |
||
175 | * @throws \coding_exception |
||
176 | */ |
||
177 | public static function create_meeting_data(&$bbbsession) { |
||
218 | |||
219 | /** |
||
220 | * Helper for returning the flag to know if the meeting is recorded. |
||
221 | * |
||
222 | * @param boolean $record |
||
223 | * @return string |
||
224 | */ |
||
225 | public static function create_meeting_data_record($record) { |
||
231 | |||
232 | /** |
||
233 | * Helper for returning the duration expected for the meeting. |
||
234 | * |
||
235 | * @param string $closingtime |
||
236 | * @return integer |
||
237 | */ |
||
238 | public static function create_meeting_data_duration($closingtime) { |
||
244 | } |
||
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.