Completed
Push — master ( 5a053e...8eeafe )
by Terrence
10:16
created

index.php ➔ getCert()   D

Complexity

Conditions 15
Paths 139

Size

Total Lines 104

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
nc 139
nop 0
dl 0
loc 104
rs 4.4733
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
// error_reporting(E_ALL); ini_set('display_errors',1);
4
5
require_once __DIR__ . '/../../vendor/autoload.php';
6
require_once __DIR__ . '/index-functions.php';
7
8
use CILogon\Service\Util;
9
use CILogon\Service\Loggit;
10
11
Util::startPHPSession();
12
13
// Check the csrf cookie against either a hidden <form> element or a
14
// PHP session variable, and get the value of the 'submit' element.
15
$submit = Util::getCsrf()->verifyCookieAndGetSubmit();
16
Util::unsetSessionVar('submit');
17
18
// Get the URL to reply to after database query.
19
$responseurl = Util::getSessionVar('responseurl');
20
21
if (($submit == 'getuser') && (strlen($responseurl) > 0)) {
22
    getUserAndRespond($responseurl);
0 ignored issues
show
Unused Code introduced by
The call to getUserAndRespond() has too many arguments starting with $responseurl.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
23
} elseif ($submit == 'pkcs12') {
24
    getPKCS12();
25
} elseif ($submit == 'certreq') {
26
    getCert();
27
} else {
28
    // If the REQUEST_URI was '/secure/getcert' then it was ECP.
29
    // Respond with an error message rather than a redirect.
30
    if (preg_match('%/secure/getcert%', Util::getServerVar('REQUEST_URI'))) {
31
        $log = new Loggit();
32
        $log->info('"/secure/getcert" error: Either CSRF check ' .
33
                   'failed, or invalid "submit" command issued.');
34
        outputError('Unable to complete ECP transaction. Either CSRF ' .
35
                    'check failed, or invalid "submit" command issued.');
36
    } else { // Redirect to $responseurl or main homepage
37
        if (strlen($responseurl) == 0) {
38
            $responseurl = 'https://' . Util::getHN();
39
        }
40
        header('Location: ' . $responseurl);
41
        exit; // No further processing necessary
42
    }
43
}
44