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

index-site.php ➔ handleAllowDelegation()   F

Complexity

Conditions 32
Paths > 20000

Size

Total Lines 235

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 32
nc 23520
nop 1
dl 0
loc 235
rs 0
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\Content;
10
use CILogon\Service\Loggit;
11
12
Util::startPHPSession();
13
14
// Check the csrf cookie against either a hidden <form> element or a
15
// PHP session variable, and get the value of the 'submit' element.
16
// Note: replace CR/LF with space for 'Show/Hide Help' buttons.
17
$retchars = array("\r\n","\n","\r");
18
$submit = str_replace(
19
    $retchars,
20
    " ",
21
    Util::getCsrf()->verifyCookieAndGetSubmit()
22
);
23
Util::unsetSessionVar('submit');
24
25
$log = new Loggit();
26
$log->info('submit="' . $submit . '"');
27
28
// First, check to see if the info related to the 'oauth_token' passed
29
// from the Community Portal exists in the current PHP session.  If
30
// so, then continue processing based on 'submit' value.  Otherwise,
31
// print out error message about bad or missing oauth_token info.
32
if (verifyOAuthToken(Util::getGetVar('oauth_token'))) {
33
    // Depending on the value of the clicked 'submit' button or the
34
    // equivalent PHP session variable, take action or print out HTML.
35
    switch ($submit) {
36
        case 'Log On': // Check for OpenID or InCommon usage.
37
        case 'Continue': // For OOI
38
            Content::handleLogOnButtonClicked();
39
            break; // End case 'Log On'
40
41
        case 'gotuser': // Return from the getuser script
42
            Content::handleGotUser();
43
            break; // End case 'gotuser'
44
45
        case 'Proceed': // Proceed after 'User Changed' or Error page
46
        case 'Done with Two-Factor':
47
            Util::verifySessionAndCall('printMainPage');
0 ignored issues
show
Documentation introduced by
'printMainPage' is of type string, but the function expects a object<CILogon\Service\function>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48
            break; // End case 'Proceed'
49
50
        case 'OK':  // User allows delegation of certificate
51
            handleAllowDelegation(strlen(Util::getPostVar('rememberok')) > 0);
52
            break; // End case 'OK'
53
54
        case 'Cancel': // User denies delegation of certificate
55
            // If user clicked 'Cancel' on the WAYF page, return to the
56
            // portal's failure URL (or Google if failure URL not set).
57
            if (Util::getPostVar('previouspage') == 'WAYF') {
58
                $failureuri = Util::getSessionVar('failureuri');
59
                $location = 'https://www.google.com/';
60
                if (strlen($failureuri) > 0) {
61
                    $location = $failureuri . "?reason=cancel";
62
                }
63
                Util::unsetAllUserSessionVars();
64
                header('Location: ' . $location);
65
                exit; // No further processing necessary
66
            } else { // 'Cancel' button on certificate delegate page clicked
67
                printCancelPage();
68
            }
69
            break; // End case 'Cancel'
70
71
        case 'Manage Two-Factor':
72
            Util::verifySessionAndCall(
73
                'CILogon\\Service\\Content::printTwoFactorPage'
0 ignored issues
show
Documentation introduced by
'CILogon\\Service\\Content::printTwoFactorPage' is of type string, but the function expects a object<CILogon\Service\function>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
            );
75
            break; // End case 'Manage Two-Factor'
76
77
        case 'Enable':   // Enable / Disable two-factor authentication
78
        case 'Disable':
79
        case 'Verify':   // Log in with Google Authenticator
80
        case 'Disable Two-Factor':
81
            $enable = !preg_match('/^Disable/', $submit);
82
            Util::verifySessionAndCall(
83
                'CILogon\\Service\\Content::handleEnableDisableTwoFactor',
0 ignored issues
show
Documentation introduced by
'CILogon\\Service\\Conte...EnableDisableTwoFactor' is of type string, but the function expects a object<CILogon\Service\function>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
84
                array($enable)
85
            );
86
            break; // End case 'Enable' / 'Disable'
87
88
        case 'I Lost My Phone':
89
            Util::verifySessionAndCall(
90
                'CILogon\\Service\\Content::handleILostMyPhone'
0 ignored issues
show
Documentation introduced by
'CILogon\\Service\\Content::handleILostMyPhone' is of type string, but the function expects a object<CILogon\Service\function>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
91
            );
92
            break; // End case 'I Lost My Phone'
93
94
        case 'Enter': // Verify Google Authenticator one time password
95
            Util::verifySessionAndCall(
96
                'CILogon\\Service\\Content::handleGoogleAuthenticatorLogin'
0 ignored issues
show
Documentation introduced by
'CILogon\\Service\\Conte...ogleAuthenticatorLogin' is of type string, but the function expects a object<CILogon\Service\function>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
            );
98
            break; // End case 'Enter'
99
100
        case 'EnterDuo': // Verify Duo Security login
101
            Util::verifySessionAndCall(
102
                'CILogon\\Service\\Content::handleDuoSecurityLogin'
0 ignored issues
show
Documentation introduced by
'CILogon\\Service\\Conte...handleDuoSecurityLogin' is of type string, but the function expects a object<CILogon\Service\function>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
103
            );
104
            break; // End case 'EnterDuo'
105
106
        case 'Show  Help ': // Toggle showing of help text on and off
107
        case 'Hide  Help ':
108
            Content::handleHelpButtonClicked();
109
            break; // End case 'Show Help' / 'Hide Help'
110
111
        default: // No submit button clicked nor PHP session submit variable set
112
            Content::handleNoSubmitButtonClicked();
113
            break; // End default case
114
    } // End switch ($submit)
115
} else { // Failed to verify oauth_token info in PHP session
116
    printBadOAuthTokenPage();
117
}
118