Conditions | 12 |
Paths | 768 |
Total Lines | 76 |
Lines | 76 |
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 |
||
47 | if ($bbbsession['administrator'] || $bbbsession['moderator']) { |
||
48 | $password = $bbbsession['modPW']; |
||
49 | } |
||
50 | $joinurl = bigbluebuttonbn_get_join_url($bbbsession['meetingid'], $bbbsession['username'], |
||
51 | $password, $bbbsession['logoutURL'], null, $bbbsession['userID'], $bbbsession['clienttype']); |
||
52 | |||
53 | return($joinurl); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Return the status of an activity [open|not_started|ended]. |
||
58 | * |
||
59 | * @param array $bbbsession |
||
60 | * @return string |
||
61 | */ |
||
62 | View Code Duplication | public static function get_activity_status(&$bbbsession) { |
|
|
|||
63 | $now = time(); |
||
64 | if (!empty($bbbsession['bigbluebuttonbn']->openingtime) && $now < $bbbsession['bigbluebuttonbn']->openingtime) { |
||
65 | // The activity has not been opened. |
||
66 | return 'not_started'; |
||
67 | } |
||
68 | if (!empty($bbbsession['bigbluebuttonbn']->closingtime) && $now > $bbbsession['bigbluebuttonbn']->closingtime) { |
||
69 | // The activity has been closed. |
||
70 | return 'ended'; |
||
71 | } |
||
72 | // The activity is open. |
||
73 | return 'open'; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Helper for preparing metadata used while creating the meeting. |
||
78 | * |
||
79 | * @param array $bbbsession |
||
80 | * @return array |
||
81 | */ |
||
82 | public static function create_meeting_metadata(&$bbbsession) { |
||
83 | return bigbluebuttonbn_create_meeting_metadata($bbbsession); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Helper to prepare data used for create meeting. |
||
88 | * @param array $bbbsession |
||
89 | * @return array |
||
90 | * @throws \coding_exception |
||
91 | */ |
||
92 | public static function create_meeting_data(&$bbbsession) { |
||
93 | $data = ['meetingID' => $bbbsession['meetingid'], |
||
94 | 'name' => bigbluebuttonbn_html2text($bbbsession['meetingname'], 64), |
||
95 | 'attendeePW' => $bbbsession['viewerPW'], |
||
96 | 'moderatorPW' => $bbbsession['modPW'], |
||
97 | 'logoutURL' => $bbbsession['logoutURL'], |
||
98 | ]; |
||
99 | $data['record'] = self::create_meeting_data_record($bbbsession['record']); |
||
100 | // Check if auto_start_record is enable. |
||
101 | View Code Duplication | if ($data['record'] == 'true' && $bbbsession['recordallfromstart']) { |
|
102 | $data['autoStartRecording'] = 'true'; |
||
103 | // Check if hide_record_button is enable. |
||
104 | if ($bbbsession['recordallfromstart'] && $bbbsession['recordhidebutton']) { |
||
105 | $data['allowStartStopRecording'] = 'false'; |
||
106 | } |
||
107 | } |
||
108 | $data['welcome'] = trim($bbbsession['welcome']); |
||
109 | // Set the duration for the meeting. |
||
110 | $durationtime = self::create_meeting_data_duration($bbbsession['bigbluebuttonbn']->closingtime); |
||
111 | View Code Duplication | if ($durationtime > 0) { |
|
112 | $data['duration'] = $durationtime; |
||
113 | $data['welcome'] .= '<br><br>'; |
||
114 | $data['welcome'] .= str_replace( |
||
115 | '%duration%', |
||
116 | (string) $durationtime, |
||
117 | get_string('bbbdurationwarning', 'bigbluebuttonbn') |
||
118 | ); |
||
119 | } |
||
120 | $voicebridge = intval($bbbsession['voicebridge']); |
||
121 | if ($voicebridge > 0 && $voicebridge < 79999) { |
||
122 | $data['voiceBridge'] = $voicebridge; |
||
123 | } |
||
160 |
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.