Conditions | 13 |
Paths | 13 |
Total Lines | 501 |
Code Lines | 119 |
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 |
||
158 | public function getSms($additionalParameters) |
||
159 | { |
||
160 | $plugin = KannelsmsPlugin::create(); |
||
161 | $tool_name = $plugin->get_lang('plugin_title'); |
||
162 | $tpl = new Template($tool_name); |
||
163 | |||
164 | switch ($additionalParameters['smsType']) { |
||
165 | case SmsPlugin::WELCOME_LOGIN_PASSWORD: |
||
166 | $userInfo = api_get_user_info($additionalParameters['userId']); |
||
167 | |||
168 | return $this->buildSms( |
||
169 | $plugin, |
||
170 | $tpl, |
||
171 | 'welcome_login_password.tpl', |
||
172 | 'WelcomeXLoginXPasswordX', |
||
173 | [ |
||
174 | api_get_setting('siteName'), |
||
175 | $userInfo['username'], |
||
176 | $additionalParameters['password'], |
||
177 | ] |
||
178 | ); |
||
179 | break; |
||
|
|||
180 | case SmsPlugin::NEW_FILE_SHARED_COURSE_BY: |
||
181 | return $this->buildSms( |
||
182 | $plugin, |
||
183 | $tpl, |
||
184 | 'new_file_shared_course_by.tpl', |
||
185 | 'XNewFileSharedCourseXByX', |
||
186 | [ |
||
187 | api_get_setting('siteName'), |
||
188 | $additionalParameters['courseTitle'], |
||
189 | $additionalParameters['userUsername'], |
||
190 | ] |
||
191 | ); |
||
192 | break; |
||
193 | case SmsPlugin::ACCOUNT_APPROVED_CONNECT: |
||
194 | return $this->buildSms( |
||
195 | $plugin, |
||
196 | $tpl, |
||
197 | 'account_approved_connect.tpl', |
||
198 | 'XAccountApprovedConnectX', |
||
199 | [ |
||
200 | api_get_setting('siteName'), |
||
201 | $tpl->params['_p']['web'], |
||
202 | ] |
||
203 | ); |
||
204 | break; |
||
205 | case SmsPlugin::NEW_COURSE_BEEN_CREATED: |
||
206 | return $this->buildSms( |
||
207 | $plugin, |
||
208 | $tpl, |
||
209 | 'new_course_been_created.tpl', |
||
210 | 'XNewCourseXBeenCreatedX', |
||
211 | [ |
||
212 | api_get_setting('siteName'), |
||
213 | $additionalParameters['courseName'], |
||
214 | $additionalParameters['creatorUsername'], |
||
215 | ] |
||
216 | ); |
||
217 | break; |
||
218 | case SmsPlugin::NEW_USER_SUBSCRIBED_COURSE: |
||
219 | return $this->buildSms( |
||
220 | $plugin, |
||
221 | $tpl, |
||
222 | 'new_user_subscribed_course.tpl', |
||
223 | 'XNewUserXSubscribedCourseX', |
||
224 | [ |
||
225 | api_get_setting('siteName'), |
||
226 | $additionalParameters['userUsername'], |
||
227 | $additionalParameters['courseCode'], |
||
228 | ] |
||
229 | ); |
||
230 | break; |
||
231 | case SmsPlugin::NEW_COURSE_SUGGESTED_TEACHER: |
||
232 | return $this->buildSms( |
||
233 | $plugin, |
||
234 | $tpl, |
||
235 | 'new_course_suggested_teacher.tpl', |
||
236 | 'XNewCourseSuggestedTeacherX', |
||
237 | [ |
||
238 | api_get_setting('siteName'), |
||
239 | $additionalParameters['userUsername'], |
||
240 | ] |
||
241 | ); |
||
242 | break; |
||
243 | case SmsPlugin::COURSE_OPENING_REQUEST_CODE_REGISTERED: |
||
244 | return $this->buildSms( |
||
245 | $plugin, |
||
246 | $tpl, |
||
247 | 'course_opening_request_code_registered.tpl', |
||
248 | 'XCourseOpeningRequestCodeXRegistered', |
||
249 | [ |
||
250 | api_get_setting('siteName'), |
||
251 | $additionalParameters['courseCode'], |
||
252 | ] |
||
253 | ); |
||
254 | break; |
||
255 | case SmsPlugin::COURSE_OPENING_REQUEST_CODE_APPROVED: |
||
256 | return $this->buildSms( |
||
257 | $plugin, |
||
258 | $tpl, |
||
259 | 'course_opening_request_course_code_approved.tpl', |
||
260 | 'XCourseOpeningRequestCourseCodeXApproved', |
||
261 | [ |
||
262 | api_get_setting('siteName'), |
||
263 | $additionalParameters['courseCode'], |
||
264 | ] |
||
265 | ); |
||
266 | break; |
||
267 | case SmsPlugin::COURSE_OPENING_REQUEST_CODE_REJECTED: |
||
268 | return $this->buildSms( |
||
269 | $plugin, |
||
270 | $tpl, |
||
271 | 'request_open_course_code_rejected.tpl', |
||
272 | 'XRequestOpenCourseCodeXReject', |
||
273 | [ |
||
274 | api_get_setting('siteName'), |
||
275 | $additionalParameters['courseCode'], |
||
276 | ] |
||
277 | ); |
||
278 | break; |
||
279 | case SmsPlugin::COURSE_OPENING_REQUEST_CODE: |
||
280 | return $this->buildSms( |
||
281 | $plugin, |
||
282 | $tpl, |
||
283 | 'course_opening_request_course_code.tpl', |
||
284 | 'XCourseOpeningRequestCourseCodeX', |
||
285 | [ |
||
286 | api_get_setting('siteName'), |
||
287 | $additionalParameters['courseCode'], |
||
288 | ] |
||
289 | ); |
||
290 | break; |
||
291 | case SmsPlugin::BEEN_SUBSCRIBED_COURSE: |
||
292 | return $this->buildSms( |
||
293 | $plugin, |
||
294 | $tpl, |
||
295 | 'been_subscribed_course.tpl', |
||
296 | 'XBeenSubscribedCourseX', |
||
297 | [ |
||
298 | api_get_setting('siteName'), |
||
299 | $additionalParameters['courseTitle'], |
||
300 | ] |
||
301 | ); |
||
302 | break; |
||
303 | case SmsPlugin::ASSIGNMENT_BEEN_CREATED_COURSE: |
||
304 | return $this->buildSms( |
||
305 | $plugin, |
||
306 | $tpl, |
||
307 | 'assignment_been_created_course.tpl', |
||
308 | 'XAssignmentBeenCreatedCourseX', |
||
309 | [ |
||
310 | api_get_setting('siteName'), |
||
311 | $additionalParameters['courseTitle'], |
||
312 | ] |
||
313 | ); |
||
314 | break; |
||
315 | // Message types to be implemented. Fill the array parameter with arguments. |
||
316 | /*case SmsPlugin::ACCOUNT_CREATED_UPDATED_LOGIN_PASSWORD: |
||
317 | return $this->buildSms( |
||
318 | $plugin, |
||
319 | $tpl, |
||
320 | 'account_created_updated_login_password.tpl', |
||
321 | 'XAccountCreatedUpdatedLoginXPasswordX', |
||
322 | array( |
||
323 | api_get_setting('siteName') |
||
324 | ) |
||
325 | ); |
||
326 | break;*/ |
||
327 | /*case SmsPlugin::PASSWORD_UPDATED_LOGIN_PASSWORD: |
||
328 | return $this->buildSms( |
||
329 | $plugin, |
||
330 | $tpl, |
||
331 | 'password_updated_login_password.tpl', |
||
332 | 'XPasswordUpdatedLoginXPasswordX', |
||
333 | array( |
||
334 | api_get_setting('siteName') |
||
335 | ) |
||
336 | ); |
||
337 | break;*/ |
||
338 | /*case SmsPlugin::REQUESTED_PASSWORD_CHANGE: |
||
339 | return $this->buildSms( |
||
340 | $plugin, |
||
341 | $tpl, |
||
342 | 'requested_password_change.tpl', |
||
343 | 'XPasswordUpdatedLoginXPasswordX', |
||
344 | array( |
||
345 | api_get_setting('siteName') |
||
346 | ) |
||
347 | ); |
||
348 | break;*/ |
||
349 | /*case SmsPlugin::RECEIVED_NEW_PERSONAL_MESSAGES: |
||
350 | return $this->buildSms( |
||
351 | $plugin, |
||
352 | $tpl, |
||
353 | 'received_new_personal_messages.tpl', |
||
354 | 'XReceivedNewPersonalMessages', |
||
355 | array( |
||
356 | api_get_setting('siteName') |
||
357 | ) |
||
358 | ); |
||
359 | break;*/ |
||
360 | /*case SmsPlugin::NEW_USER_PENDING_APPROVAL: |
||
361 | return $this->buildSms( |
||
362 | $plugin, |
||
363 | $tpl, |
||
364 | 'new_user_pending_approval.tpl', |
||
365 | 'XNewUserXPendingApproval', |
||
366 | array( |
||
367 | api_get_setting('siteName') |
||
368 | ) |
||
369 | ); |
||
370 | break;*/ |
||
371 | /*case SmsPlugin::POSTED_FORUM_COURSE: |
||
372 | return $this->buildSms( |
||
373 | $plugin, |
||
374 | $tpl, |
||
375 | 'posted_forum_course.tpl', |
||
376 | 'XXPostedForumXCourseX', |
||
377 | array( |
||
378 | api_get_setting('siteName') |
||
379 | ) |
||
380 | ); |
||
381 | break;*/ |
||
382 | /*case SmsPlugin::CHECK_EMAIL_CONNECT_MORE_INFO: |
||
383 | return $this->buildSms( |
||
384 | $plugin, |
||
385 | $tpl, |
||
386 | 'check_email_connect_more_info.tpl', |
||
387 | 'XXXCheckEmailConnectMoreInfo', |
||
388 | array( |
||
389 | api_get_setting('siteName') |
||
390 | ) |
||
391 | ); |
||
392 | break;*/ |
||
393 | /*case SmsPlugin::STUDENT_ANSWERED_TEST: |
||
394 | return $this->buildSms( |
||
395 | $plugin, |
||
396 | $tpl, |
||
397 | 'student_answered_test.tpl', |
||
398 | 'XXStudentXAnsweredTestX', |
||
399 | array( |
||
400 | api_get_setting('siteName') |
||
401 | ) |
||
402 | ); |
||
403 | break;*/ |
||
404 | /*case SmsPlugin::STUDENT_ANSWERED_TEST_OPEN_QUESTION: |
||
405 | return $this->buildSms( |
||
406 | $plugin, |
||
407 | $tpl, |
||
408 | 'student_answered_test_open_question.tpl', |
||
409 | 'XXStudentXAnsweredTestXOpenQuestion', |
||
410 | array( |
||
411 | api_get_setting('siteName') |
||
412 | ) |
||
413 | ); |
||
414 | break;*/ |
||
415 | /*case SmsPlugin::STUDENT_ANSWERED_TEST_VOICE_QUESTION: |
||
416 | return $this->buildSms( |
||
417 | $plugin, |
||
418 | $tpl, |
||
419 | 'student_answered_test_voice_question.tpl', |
||
420 | 'XXStudentXAnsweredTestXVoiceQuestion', |
||
421 | array( |
||
422 | api_get_setting('siteName') |
||
423 | ) |
||
424 | ); |
||
425 | break;*/ |
||
426 | /*case SmsPlugin::ANSWER_OPEN_QUESTION_TEST_REVIEWED: |
||
427 | return $this->buildSms( |
||
428 | $plugin, |
||
429 | $tpl, |
||
430 | 'answer_open_question_test_reviewed.tpl', |
||
431 | 'XXAnswerOpenQuestionTestXReviewed', |
||
432 | array( |
||
433 | api_get_setting('siteName') |
||
434 | ) |
||
435 | ); |
||
436 | break;*/ |
||
437 | /*case SmsPlugin::NEW_THREAD_STARTED_FORUM: |
||
438 | return $this->buildSms( |
||
439 | $plugin, |
||
440 | $tpl, |
||
441 | 'new_thread_started_forum.tpl', |
||
442 | 'XXNewThreadXStartedForumX', |
||
443 | array( |
||
444 | api_get_setting('siteName') |
||
445 | ) |
||
446 | ); |
||
447 | break;*/ |
||
448 | /*case SmsPlugin::NEW_ANSWER_POSTED_FORUM: |
||
449 | return $this->buildSms( |
||
450 | $plugin, |
||
451 | $tpl, |
||
452 | 'new_answer_posted_forum.tpl', |
||
453 | 'XXNewAnswerPostedXForumX', |
||
454 | array( |
||
455 | api_get_setting('siteName') |
||
456 | ) |
||
457 | ); |
||
458 | break;*/ |
||
459 | /*case SmsPlugin::NEW_SYSTEM_ANNOUNCEMENT_ADDED: |
||
460 | return $this->buildSms( |
||
461 | $plugin, |
||
462 | $tpl, |
||
463 | 'new_system_announcement_added.tpl', |
||
464 | 'XXNewSystemAnnouncementAdded', |
||
465 | array( |
||
466 | api_get_setting('siteName') |
||
467 | ) |
||
468 | ); |
||
469 | break;*/ |
||
470 | /*case SmsPlugin::TEST_NEW_SYSTEM_ANNOUNCEMENT_ADDED: |
||
471 | return $this->buildSms( |
||
472 | $plugin, |
||
473 | $tpl, |
||
474 | 'test_new_system_announcement_added.tpl', |
||
475 | 'XTestXNewSystemAnnouncementAdded', |
||
476 | array( |
||
477 | api_get_setting('siteName') |
||
478 | ) |
||
479 | ); |
||
480 | break;*/ |
||
481 | /*case SmsPlugin::SYSTEM_ANNOUNCEMENT_UPDATE: |
||
482 | return $this->buildSms( |
||
483 | $plugin, |
||
484 | $tpl, |
||
485 | 'system_announcement_update.tpl', |
||
486 | 'XXSystemAnnouncementUpdate', |
||
487 | array( |
||
488 | api_get_setting('siteName') |
||
489 | ) |
||
490 | ); |
||
491 | break;*/ |
||
492 | /*case SmsPlugin::TEST_SYSTEM_ANNOUNCEMENT_UPDATE: |
||
493 | return $this->buildSms( |
||
494 | $plugin, |
||
495 | $tpl, |
||
496 | 'test_system_announcement_update.tpl', |
||
497 | 'XXSystemAnnouncementUpdate', |
||
498 | array( |
||
499 | api_get_setting('siteName') |
||
500 | ) |
||
501 | ); |
||
502 | break;*/ |
||
503 | /*case SmsPlugin::USER_UPLOADED_ASSIGNMENT_COURSE_STUDENT_SUBMITS_PAPER: |
||
504 | return $this->buildSms( |
||
505 | $plugin, |
||
506 | $tpl, |
||
507 | 'user_uploaded_assignment_course_student_submits_paper.tpl', |
||
508 | 'XUserXUploadedAssignmentXCourseXStudentSubmitsPaper', |
||
509 | array( |
||
510 | api_get_setting('siteName') |
||
511 | ) |
||
512 | ); |
||
513 | break;*/ |
||
514 | /*case SmsPlugin::USER_UPLOADED_ASSIGNMENT_CHECK_STUDENT_SUBMITS_PAPER: |
||
515 | return $this->buildSms( |
||
516 | $plugin, |
||
517 | $tpl, |
||
518 | 'user_uploaded_assignment_check_student_submits_paper.tpl', |
||
519 | 'XUserXUploadedAssignmentXCheckXStudentSubmitsPaper', |
||
520 | array( |
||
521 | api_get_setting('siteName') |
||
522 | ) |
||
523 | ); |
||
524 | break;*/ |
||
525 | /*case SmsPlugin::USER_UPLOADED_ASSIGNMENT_COURSE: |
||
526 | return $this->buildSms( |
||
527 | $plugin, |
||
528 | $tpl, |
||
529 | 'user_uploaded_assignment_course.tpl', |
||
530 | 'XUserXUploadedAssignmentXCourseX', |
||
531 | array( |
||
532 | api_get_setting('siteName') |
||
533 | ) |
||
534 | ); |
||
535 | break;*/ |
||
536 | /*case SmsPlugin::USER_UPLOADED_ASSIGNMENT_CHECK: |
||
537 | return $this->buildSms( |
||
538 | $plugin, |
||
539 | $tpl, |
||
540 | 'user_uploaded_assignment_check.tpl', |
||
541 | 'XUserXUploadedAssignmentXCheckX', |
||
542 | array( |
||
543 | api_get_setting('siteName') |
||
544 | ) |
||
545 | ); |
||
546 | break;*/ |
||
547 | /*case SmsPlugin::SUBSCRIBED_SESSION: |
||
548 | return $this->buildSms( |
||
549 | $plugin, |
||
550 | $tpl, |
||
551 | 'subscribed_session.tpl', |
||
552 | 'XSubscribedSessionX', |
||
553 | array( |
||
554 | api_get_setting('siteName') |
||
555 | ) |
||
556 | ); |
||
557 | break;*/ |
||
558 | /*case SmsPlugin::SUBSCRIBED_SESSION_CSV: |
||
559 | return $this->buildSms( |
||
560 | $plugin, |
||
561 | $tpl, |
||
562 | 'subscribed_session_csv.tpl', |
||
563 | 'XSubscribedSessionXCSV', |
||
564 | array( |
||
565 | api_get_setting('siteName') |
||
566 | ) |
||
567 | ); |
||
568 | break;*/ |
||
569 | /*case SmsPlugin::USER_SUGGESTED_BE_FRIENDS: |
||
570 | return $this->buildSms( |
||
571 | $plugin, |
||
572 | $tpl, |
||
573 | 'user_suggested_be_friends.tpl', |
||
574 | 'XUserXSuggestedBeFriends', |
||
575 | array( |
||
576 | api_get_setting('siteName') |
||
577 | ) |
||
578 | ); |
||
579 | break;*/ |
||
580 | /*case SmsPlugin::USER_ANSWERED_INBOX_MESSAGE: |
||
581 | return $this->buildSms( |
||
582 | $plugin, |
||
583 | $tpl, |
||
584 | 'user_answered_inbox_message.tpl', |
||
585 | 'XUserXAnsweredInboxMessage', |
||
586 | array( |
||
587 | api_get_setting('siteName') |
||
588 | ) |
||
589 | ); |
||
590 | break;*/ |
||
591 | /*case SmsPlugin::BEEN_INVITED_JOIN_GROUP: |
||
592 | return $this->buildSms( |
||
593 | $plugin, |
||
594 | $tpl, |
||
595 | 'been_invited_join_group.tpl', |
||
596 | 'XBeenInvitedJoinGroupX', |
||
597 | array( |
||
598 | api_get_setting('siteName') |
||
599 | ) |
||
600 | ); |
||
601 | break;*/ |
||
602 | /*case SmsPlugin::MESSAGES_SENT_EDITED_GROUP_EDITED: |
||
603 | return $this->buildSms( |
||
604 | $plugin, |
||
605 | $tpl, |
||
606 | 'messages_sent_edited_group_edited.tpl', |
||
607 | 'XMessagesSentEditedGroupXEdited', |
||
608 | array( |
||
609 | api_get_setting('siteName') |
||
610 | ) |
||
611 | ); |
||
612 | break;*/ |
||
613 | /*case SmsPlugin::MESSAGES_SENT_EDITED_GROUP_ADDED: |
||
614 | return $this->buildSms( |
||
615 | $plugin, |
||
616 | $tpl, |
||
617 | 'messages_sent_edited_group_added.tpl', |
||
618 | 'XMessagesSentEditedGroupXAdded', |
||
619 | array( |
||
620 | api_get_setting('siteName') |
||
621 | ) |
||
622 | ); |
||
623 | break;*/ |
||
624 | /*case SmsPlugin::BEEN_INVITED_COMPLETE_SURVEY_COURSE: |
||
625 | return $this->buildSms( |
||
626 | $plugin, |
||
627 | $tpl, |
||
628 | 'been_invited_complete_survey_course.tpl', |
||
629 | 'XBeenInvitedCompleteSurveyXCourseX', |
||
630 | array( |
||
631 | api_get_setting('siteName') |
||
632 | ) |
||
633 | ); |
||
634 | break;*/ |
||
635 | /*case SmsPlugin::REMINDER_ASSIGNMENT_COURSE_DUE: |
||
636 | return $this->buildSms( |
||
637 | $plugin, |
||
638 | $tpl, |
||
639 | 'reminder_assignment_course_due.tpl', |
||
640 | 'XReminderAssignmentXCourseXDue', |
||
641 | array( |
||
642 | api_get_setting('siteName') |
||
643 | ) |
||
644 | ); |
||
645 | break;*/ |
||
646 | /*case SmsPlugin::USER_DETAILS_MODIFIED: |
||
647 | return $this->buildSms( |
||
648 | $plugin, |
||
649 | $tpl, |
||
650 | 'user_details_modified.tpl', |
||
651 | 'XUserDetailsModified', |
||
652 | array( |
||
653 | api_get_setting('siteName') |
||
654 | ) |
||
655 | ); |
||
656 | break;*/ |
||
657 | default: |
||
658 | return ''; |
||
659 | } |
||
662 |
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.