Conditions | 25 |
Paths | 39 |
Total Lines | 178 |
Lines | 23 |
Ratio | 12.92 % |
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 |
||
55 | public static function mobile_course_view($args) { |
||
56 | |||
57 | global $OUTPUT, $SESSION; |
||
58 | |||
59 | $args = (object) $args; |
||
60 | $viewinstance = bigbluebuttonbn_view_validator($args->cmid, null); |
||
|
|||
61 | if (!$viewinstance) { |
||
62 | $error = get_string('view_error_url_missing_parameters', 'bigbluebuttonbn'); |
||
63 | return(self::mobile_print_error($error)); |
||
64 | } |
||
65 | |||
66 | $bbbsession = bigbluebutton::build_bbb_session_fromviewinstance($viewinstance); |
||
67 | |||
68 | // Create variables for easy access. |
||
69 | $bigbluebuttonbn = $viewinstance['bigbluebuttonbn']; |
||
70 | $serverversion = $bbbsession['serverversion']; |
||
71 | $cm = $bbbsession['cm']; |
||
72 | $course = $bbbsession['course']; |
||
73 | $context = $bbbsession['context']; |
||
74 | |||
75 | // Check activity status. |
||
76 | $activitystatus = \mod_bigbluebuttonbn\locallib\mobileview::get_activity_status($bbbsession); |
||
77 | if ($activitystatus == 'not_started') { |
||
78 | $message = get_string('view_message_conference_not_started', 'bigbluebuttonbn'); |
||
79 | |||
80 | $notstarted = array(); |
||
81 | $notstarted['starts_at'] = ''; |
||
82 | $notstarted['ends_at'] = ''; |
||
83 | if (!empty($bigbluebuttonbn->openingtime)) { |
||
84 | $notstarted['starts_at'] = sprintf( |
||
85 | '%s: %s', |
||
86 | get_string('mod_form_field_openingtime', 'bigbluebuttonbn'), |
||
87 | userdate($bigbluebuttonbn->openingtime) |
||
88 | ); |
||
89 | } |
||
90 | if (!empty($bigbluebuttonbn->closingtime)) { |
||
91 | $notstarted['ends_at'] = sprintf( |
||
92 | '%s: %s', |
||
93 | get_string('mod_form_field_closingtime', 'bigbluebuttonbn'), |
||
94 | userdate($bigbluebuttonbn->closingtime) |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message, $notstarted)); |
||
99 | } |
||
100 | if ($activitystatus == 'ended') { |
||
101 | $message = get_string('view_message_conference_has_ended', 'bigbluebuttonbn'); |
||
102 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
103 | } |
||
104 | |||
105 | // Check if the BBB server is working. |
||
106 | View Code Duplication | if (is_null($serverversion)) { |
|
107 | |||
108 | if ($bbbsession['administrator']) { |
||
109 | $error = get_string('view_error_unable_join', 'bigbluebuttonbn'); |
||
110 | } else if ($bbbsession['moderator']) { |
||
111 | $error = get_string('view_error_unable_join_teacher', 'bigbluebuttonbn'); |
||
112 | } else { |
||
113 | $error = get_string('view_error_unable_join_student', 'bigbluebuttonbn'); |
||
114 | } |
||
115 | |||
116 | return(self::mobile_print_error($error)); |
||
117 | } |
||
118 | |||
119 | // Mark viewed by user (if required). |
||
120 | $completion = new \completion_info($course); |
||
121 | $completion->set_module_viewed($cm); |
||
122 | |||
123 | // Validate if the user is in a role allowed to join. |
||
124 | if (!has_capability('moodle/category:manage', $context) && |
||
125 | !has_capability('mod/bigbluebuttonbn:join', $context)) { |
||
126 | $error = get_string('view_nojoin', 'bigbluebuttonbn'); |
||
127 | return(self::mobile_print_error($error)); |
||
128 | } |
||
129 | |||
130 | // Initialize session variable used across views. |
||
131 | $SESSION->bigbluebuttonbn_bbbsession = $bbbsession; |
||
132 | |||
133 | // Logic of bbb_view for join to session. |
||
134 | // If user is not administrator nor moderator (user is student) and waiting is required. |
||
135 | if (!$bbbsession['administrator'] && !$bbbsession['moderator'] && $bbbsession['wait']) { |
||
136 | $canjoin = \mod_bigbluebuttonbn\locallib\bigbluebutton::can_join_meeting($args->cmid); |
||
137 | if (!$canjoin['can_join']) { |
||
138 | $message = get_string('view_message_conference_wait_for_moderator', 'bigbluebuttonbn'); |
||
139 | return (self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | // See if the BBB session is already in progress. |
||
144 | if (!bigbluebuttonbn_is_meeting_running($bbbsession['meetingid'])) { |
||
145 | |||
146 | // The meeting doesnt exist in BBB server, must be created. |
||
147 | $response = bigbluebuttonbn_get_create_meeting_array( |
||
148 | \mod_bigbluebuttonbn\locallib\mobileview::create_meeting_data($bbbsession), |
||
149 | \mod_bigbluebuttonbn\locallib\mobileview::create_meeting_metadata($bbbsession), |
||
150 | $bbbsession['presentation']['name'], |
||
151 | $bbbsession['presentation']['url'] |
||
152 | ); |
||
153 | |||
154 | View Code Duplication | if (empty($response)) { |
|
155 | // The BBB server is failing. |
||
156 | if ($bbbsession['administrator']) { |
||
157 | $e = get_string('view_error_unable_join', 'bigbluebuttonbn'); |
||
158 | } else if ($bbbsession['moderator']) { |
||
159 | $e = get_string('view_error_unable_join_teacher', 'bigbluebuttonbn'); |
||
160 | } else { |
||
161 | $e = get_string('view_error_unable_join_student', 'bigbluebuttonbn'); |
||
162 | } |
||
163 | return(self::mobile_print_error($e)); |
||
164 | } |
||
165 | if ($response['returncode'] == 'FAILED') { |
||
166 | // The meeting could not be created. |
||
167 | $errorkey = bigbluebuttonbn_get_error_key($response['messageKey'], 'view_error_create'); |
||
168 | $e = get_string($errorkey, 'bigbluebuttonbn'); |
||
169 | return(self::mobile_print_error($e)); |
||
170 | } |
||
171 | if ($response['hasBeenForciblyEnded'] == 'true') { |
||
172 | $e = get_string('index_error_forciblyended', 'bigbluebuttonbn'); |
||
173 | return(self::mobile_print_error($e)); |
||
174 | } |
||
175 | |||
176 | // Event meeting created. |
||
177 | bigbluebuttonbn_event_log(\mod_bigbluebuttonbn\event\events::$events['meeting_create'], $bigbluebuttonbn); |
||
178 | // Insert a record that meeting was created. |
||
179 | $overrides = array('meetingid' => $bbbsession['meetingid']); |
||
180 | $meta = '{"record":'.($bbbsession['record'] ? 'true' : 'false').'}'; |
||
181 | bigbluebuttonbn_log($bbbsession['bigbluebuttonbn'], BIGBLUEBUTTONBN_LOG_EVENT_CREATE, $overrides, $meta); |
||
182 | } |
||
183 | |||
184 | // It is part of 'bigbluebuttonbn_bbb_view_join_meeting' in bbb_view. |
||
185 | // Update the cache. |
||
186 | $meetinginfo = bigbluebuttonbn_get_meeting_info($bbbsession['meetingid'], BIGBLUEBUTTONBN_UPDATE_CACHE); |
||
187 | if ($bbbsession['userlimit'] > 0 && intval($meetinginfo['participantCount']) >= $bbbsession['userlimit']) { |
||
188 | // No more users allowed to join. |
||
189 | $message = get_string('view_error_userlimit_reached', 'bigbluebuttonbn'); |
||
190 | return(self::mobile_print_notification($bigbluebuttonbn, $cm, $message)); |
||
191 | } |
||
192 | |||
193 | // Build final url to BBB. |
||
194 | $bbbsession['createtime'] = $meetinginfo['createTime']; |
||
195 | $urltojoin = \mod_bigbluebuttonbn\locallib\mobileview::build_url_join_session($bbbsession); |
||
196 | |||
197 | // Check groups access and show message. |
||
198 | $msjgroup = array(); |
||
199 | $groupmode = groups_get_activity_groupmode($bbbsession['cm']); |
||
200 | if ($groupmode != NOGROUPS) { |
||
201 | $msjgroup = array("message" => get_string('view_mobile_message_groups_not_supported', |
||
202 | 'bigbluebuttonbn')); |
||
203 | } |
||
204 | |||
205 | $data = array( |
||
206 | 'bigbluebuttonbn' => $bigbluebuttonbn, |
||
207 | 'bbbsession' => (object) $bbbsession, |
||
208 | 'msjgroup' => $msjgroup, |
||
209 | 'urltojoin' => $urltojoin, |
||
210 | 'cmid' => $cm->id, |
||
211 | 'courseid' => $course->id |
||
212 | ); |
||
213 | |||
214 | // We want to show a notification when user excedded 45 seconds without click button. |
||
215 | $jstimecreatedmeeting = 'setTimeout(function(){ |
||
216 | document.getElementById("bigbluebuttonbn-mobile-notifications").style.display = "block"; |
||
217 | document.getElementById("bigbluebuttonbn-mobile-join").disabled = true; |
||
218 | document.getElementById("bigbluebuttonbn-mobile-meetingready").style.display = "none"; |
||
219 | }, 45000);'; |
||
220 | |||
221 | return array( |
||
222 | 'templates' => array( |
||
223 | array( |
||
224 | 'id' => 'main', |
||
225 | 'html' => $OUTPUT->render_from_template('mod_bigbluebuttonbn/mobile_view_page', $data), |
||
226 | ), |
||
227 | ), |
||
228 | 'javascript' => $jstimecreatedmeeting, |
||
229 | 'otherdata' => '', |
||
230 | 'files' => '' |
||
231 | ); |
||
232 | } |
||
233 | |||
291 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: