Conditions | 3 |
Paths | 4 |
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 |
||
98 | function bigbluebuttonbn_create_lti_parameters($endpoint, $playerurl) { |
||
99 | global $CFG, $COURSE, $USER; |
||
100 | |||
101 | // Get consumerkey and consumersecret from filter_opencast. |
||
102 | $consumerkey = get_config('filter_opencast', 'consumerkey'); |
||
103 | $consumersecret = get_config('filter_opencast', 'consumersecret'); |
||
104 | |||
105 | $helper = new oauth_helper(array('oauth_consumer_key' => $consumerkey, |
||
106 | 'oauth_consumer_secret' => $consumersecret)); |
||
107 | |||
108 | // Set all necessary parameters. |
||
109 | $params = array(); |
||
110 | $params['oauth_version'] = '1.0'; |
||
111 | $params['oauth_nonce'] = $helper->get_nonce(); |
||
112 | $params['oauth_timestamp'] = $helper->get_timestamp(); |
||
113 | $params['oauth_consumer_key'] = $consumerkey; |
||
114 | |||
115 | $params['context_id'] = $COURSE->id; |
||
116 | $params['context_label'] = trim($COURSE->shortname); |
||
117 | $params['context_title'] = trim($COURSE->fullname); |
||
118 | $params['resource_link_id'] = 'o' . random_int(1000, 9999) . '-' . random_int(1000, 9999); |
||
119 | $params['resource_link_title'] = 'Opencast'; |
||
120 | $params['context_type'] = ($COURSE->format == 'site') ? 'Group' : 'CourseSection'; |
||
121 | $params['launch_presentation_locale'] = current_language(); |
||
122 | $params['ext_lms'] = 'moodle-2'; |
||
123 | $params['tool_consumer_info_product_family_code'] = 'moodle'; |
||
124 | $params['tool_consumer_info_version'] = strval($CFG->version); |
||
125 | $params['oauth_callback'] = 'about:blank'; |
||
126 | $params['lti_version'] = 'LTI-1p0'; |
||
127 | $params['lti_message_type'] = 'basic-lti-launch-request'; |
||
128 | $urlparts = parse_url($CFG->wwwroot); |
||
129 | $params['tool_consumer_instance_guid'] = $urlparts['host']; |
||
130 | $params['custom_tool'] = $playerurl; |
||
131 | |||
132 | // User data. |
||
133 | $params['user_id'] = $USER->id; |
||
134 | $params['lis_person_name_given'] = $USER->firstname; |
||
135 | $params['lis_person_name_family'] = $USER->lastname; |
||
136 | $params['lis_person_name_full'] = $USER->firstname . ' ' . $USER->lastname; |
||
137 | $params['ext_user_username'] = $USER->username; |
||
138 | $params['lis_person_contact_email_primary'] = $USER->email; |
||
139 | $params['roles'] = lti_get_ims_role($USER, null, $COURSE->id, false); |
||
140 | |||
141 | if (!empty($CFG->mod_lti_institution_name)) { |
||
142 | $params['tool_consumer_instance_name'] = trim(html_to_text($CFG->mod_lti_institution_name, 0)); |
||
143 | } else { |
||
144 | $params['tool_consumer_instance_name'] = get_site()->shortname; |
||
145 | } |
||
146 | |||
147 | $params['launch_presentation_document_target'] = 'iframe'; |
||
148 | $params['oauth_signature_method'] = 'HMAC-SHA1'; |
||
149 | $signedparams = lti_sign_parameters($params, $endpoint, "POST", $consumerkey, $consumersecret); |
||
150 | $params['oauth_signature'] = $signedparams['oauth_signature']; |
||
151 | |||
152 | return $params; |
||
153 | } |
||
154 | |||
179 |