| Conditions | 9 | 
| Paths | 98 | 
| Total Lines | 56 | 
| 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 | ||
| 59 |     public function __construct($course, $bigbluebuttonbn, $tc) { | ||
| 60 | global $SESSION, $PAGE; | ||
| 61 | $bbbsession = $SESSION->bigbluebuttonbn_bbbsession; | ||
| 62 | $options = bigbluebuttonbn_import_get_courses_for_select($bbbsession); | ||
| 63 | $selected = isset($options[$tc]) ? $tc : ''; | ||
| 64 |         $this->context['backactionurl'] = plugin::necurl('/mod/bigbluebuttonbn/view.php'); | ||
| 65 | $this->context['cmid'] = $PAGE->cm->id; | ||
| 66 |         if (!empty($options)) { | ||
| 67 | $selectoptions = []; | ||
| 68 |             $toadd = ['value' => '', 'label' => get_string('choosedots')]; | ||
| 69 |             if ('' == $tc) { | ||
| 70 | $toadd['selected'] = true; | ||
| 71 | } | ||
| 72 | $selectoptions[] = $toadd; | ||
| 73 |             foreach ($options as $key => $option) { | ||
| 74 | $toadd = ['value' => $key, 'label' => $option]; | ||
| 75 |                 if ($key == $tc) { | ||
| 76 | $toadd['selected'] = true; | ||
| 77 | } | ||
| 78 | $selectoptions[] = $toadd; | ||
| 79 | } | ||
| 80 | $this->context['hascontent'] = true; | ||
| 81 | $this->context['selectoptions'] = $selectoptions; | ||
| 82 | // Get course recordings. | ||
| 83 | $bigbluebuttonbnid = null; | ||
| 84 |             if ($course->id == $selected) { | ||
| 85 | $bigbluebuttonbnid = $bigbluebuttonbn->id; | ||
| 86 | } | ||
| 87 | $recordings = bigbluebuttonbn_get_allrecordings( | ||
| 88 | $selected, $bigbluebuttonbnid, false, | ||
| 89 |                 (boolean)\mod_bigbluebuttonbn\locallib\config::get('importrecordings_from_deleted_enabled') | ||
| 90 | ); | ||
| 91 | // Exclude the ones that are already imported. | ||
| 92 |             if (!empty($recordings)) { | ||
| 93 | $recordings = bigbluebuttonbn_unset_existent_recordings_already_imported( | ||
| 94 | $recordings, $course->id, $bigbluebuttonbn->id | ||
| 95 | ); | ||
| 96 | } | ||
| 97 | // Store recordings (indexed) in a session variable. | ||
| 98 | $SESSION->bigbluebuttonbn_importrecordings = $recordings; | ||
| 99 | // Proceed with rendering. | ||
| 100 |             if (!empty($recordings)) { | ||
| 101 | $this->context['recordings'] = true; | ||
| 102 | $this->context['recordingtable'] = bigbluebuttonbn_output_recording_table($bbbsession, $recordings, ['import']); | ||
| 103 | } | ||
| 104 | // JavaScript for locales. | ||
| 105 | $PAGE->requires->strings_for_js(array_keys(bigbluebuttonbn_get_strings_for_js()), 'bigbluebuttonbn'); | ||
| 106 | // Require JavaScript modules. | ||
| 107 |             $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-imports', 'M.mod_bigbluebuttonbn.imports.init', | ||
| 108 |                 array(array('bn' => $bigbluebuttonbn->id, 'tc' => $selected))); | ||
| 109 |             $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-broker', 'M.mod_bigbluebuttonbn.broker.init', | ||
| 110 | array()); | ||
| 111 |             $PAGE->requires->yui_module('moodle-mod_bigbluebuttonbn-recordings', 'M.mod_bigbluebuttonbn.recordings.init', | ||
| 112 |                 array('recordings_html' => true)); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 125 | } |