Conditions | 16 |
Paths | 97 |
Total Lines | 110 |
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 |
||
228 | function getCert() |
||
229 | { |
||
230 | $log = new Loggit(); |
||
231 | |||
232 | // Verify that a non-empty certreq <form> variable was posted |
||
233 | $certreq = Util::getPostVar('certreq'); |
||
234 | if (strlen($certreq) == 0) { |
||
235 | $log->info('ECP certreq error: Missing certificate request.'); |
||
236 | outputError('Missing certificate request.'); |
||
237 | return; // ERROR means no further processing is necessary |
||
238 | } |
||
239 | |||
240 | getUID(); // Get the user's database user ID, put info in PHP session |
||
241 | |||
242 | $skin = Util::getSkin(); |
||
243 | $skin->init(); // Check for forced skin |
||
244 | |||
245 | // If 'status' is not STATUS_OK*, then return error message |
||
246 | if (Util::getSessionVar('status') & 1) { // Bad status codes are odd |
||
247 | $errstr = array_search(Util::getSessionVar('status'), DBService::$STATUS); |
||
248 | $log->info('ECP certreq error: ' . $errstr . '.'); |
||
249 | outputError($errstr); |
||
250 | Util::unsetAllUserSessionVars(); |
||
251 | return; // ERROR means no further processing is necessary |
||
252 | } |
||
253 | |||
254 | // CIL-624 Check if X509 certs are disabled |
||
255 | if ((defined('DISABLE_X509')) && (DISABLE_X509 === true)) { |
||
256 | $log->info('ECP certreq error: Downloading certificates is ' . |
||
257 | 'disabled due to DISABLE_X509.'); |
||
258 | outputError('Downloading certificates is disabled.'); |
||
259 | Util::unsetAllUserSessionVars(); |
||
260 | return; // ERROR means no further processing is necessary |
||
261 | } |
||
262 | |||
263 | // Verify myproxy-logon binary is configured |
||
264 | $disabledbyconf = ((!defined('MYPROXY_LOGON')) || (empty(MYPROXY_LOGON))); |
||
265 | if ($disabledbyconf) { |
||
266 | $log->info('ECP certreq error: Downloading certificates is ' . |
||
267 | 'disabled due to myproxy-logon not configured.'); |
||
268 | outputError('Downloading certificates is disabled.'); |
||
269 | Util::unsetAllUserSessionVars(); |
||
270 | return; // ERROR means no further processing is necessary |
||
271 | } |
||
272 | |||
273 | $shibarray = Util::getIdpList()->getShibInfo(); |
||
274 | if (Util::isEduGAINAndGetCert(@$shibarray['Identity Provider'], @$shibarray['Organization Name'])) { |
||
275 | $log->info('ECP certreq error: Failed to get cert due to eduGAIN IdP restriction.'); |
||
276 | outputError('Failed to get cert due to eduGAIN IdP restriction.'); |
||
277 | return; // ERROR means no further processing is necessary |
||
278 | } |
||
279 | |||
280 | // Get the certificate lifetime. Set to a default value if not set. |
||
281 | $certlifetime = (int)(Util::getPostVar('certlifetime')); |
||
282 | if ($certlifetime == 0) { // If not specified, set to default value |
||
283 | $defaultlifetime = $skin->getConfigOption('ecp', 'defaultlifetime'); |
||
284 | if ((!is_null($defaultlifetime)) && ((int)$defaultlifetime > 0)) { |
||
285 | $certlifetime = (int)$defaultlifetime; |
||
286 | } else { |
||
287 | $certlifetime = MyProxy::getDefaultLifetime(); |
||
288 | } |
||
289 | } |
||
290 | |||
291 | // Make sure lifetime is within acceptable range. 277 hrs = 1000000 secs. |
||
292 | list($minlifetime, $maxlifetime) = Util::getMinMaxLifetimes('ecp', 277); |
||
293 | if ($certlifetime < $minlifetime) { |
||
294 | $certlifetime = $minlifetime; |
||
295 | } elseif ($certlifetime > $maxlifetime) { |
||
296 | $certlifetime = $maxlifetime; |
||
297 | } |
||
298 | |||
299 | // Make sure that the user's MyProxy username is available. |
||
300 | $dn = Util::getSessionVar('distinguished_name'); |
||
301 | if (strlen($dn) > 0) { |
||
302 | // Append extra info, such as 'skin', to be processed by MyProxy. |
||
303 | $skin->setMyProxyInfo(); |
||
304 | $myproxyinfo = Util::getSessionVar('myproxyinfo'); |
||
305 | if (strlen($myproxyinfo) > 0) { |
||
306 | $dn .= " $myproxyinfo"; |
||
307 | } |
||
308 | // Attempt to fetch a credential from the MyProxy server |
||
309 | $cert = MyProxy::getMyProxyCredential( |
||
310 | $dn, |
||
311 | '', |
||
312 | MYPROXY_HOST, |
||
313 | Util::getLOAPort(), |
||
314 | $certlifetime, |
||
315 | MYPROXY_CLIENT_CRED, |
||
316 | '', |
||
317 | $certreq |
||
318 | ); |
||
319 | |||
320 | if (strlen($cert) > 0) { // Successfully got a certificate! |
||
321 | $log->info('ECP getcert success!'); |
||
322 | // CIL-507 Special log message for XSEDE |
||
323 | $email = Util::getSessionVar('email'); |
||
324 | $log->info("USAGE email=\"$email\" client=\"ECP\""); |
||
325 | Util::logXSEDEUsage('ECP', $email); |
||
326 | |||
327 | header('Content-type: text/plain'); |
||
328 | echo $cert; |
||
329 | } else { // The myproxy-logon command failed - shouldn't happen! |
||
330 | $log->info('ECP certreq error: MyProxy unable to create certificate.'); |
||
331 | outputError('Error! MyProxy unable to create certificate.'); |
||
332 | } |
||
333 | } else { // Couldn't find the 'distinguished_name' PHP session value |
||
334 | $log->info('ECP certreq error: Missing \'distinguished_name\' session value.'); |
||
335 | outputError('Cannot create certificate due to missing attributes.'); |
||
336 | } |
||
337 | } |
||
338 | |||
356 |
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.