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

index-site.php ➔ printLogOff()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 16
nop 0
dl 0
loc 85
rs 8.0161
c 0
b 0
f 0

How to fix   Long Method   

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\ShibError;
11
use CILogon\Service\Loggit;
12
13
Util::startPHPSession();
14
15
// Util::startTiming();
16
// Util::$timeit->printTime('MAIN Program START...');
17
18
// Check for a Shibboleth error and handle it
19
$shiberror = new ShibError();
20
21
// Check the csrf cookie against either a hidden <form> element or a
22
// PHP session variable, and get the value of the 'submit' element.
23
// Note: replace CR/LF with space for 'Show/Hide Help' buttons.
24
$retchars = array("\r\n","\n","\r");
25
$submit = str_replace(
26
    $retchars,
27
    " ",
28
    Util::getCsrf()->verifyCookieAndGetSubmit()
29
);
30
Util::unsetSessionVar('submit');
31
32
$log = new Loggit();
33
$log->info('submit="' . $submit . '"');
34
35
// Depending on the value of the clicked 'submit' button or the
36
// equivalent PHP session variable, take action or print out HTML.
37
switch ($submit) {
38
    case 'Log On': // Check for OpenID or InCommon usage.
39
    case 'Continue': // For OOI
40
        Content::handleLogOnButtonClicked();
41
        break; // End case 'Log On'
42
43
    case 'Log Off':   // Click the 'Log Off' button
44
        printLogonPage(true);
0 ignored issues
show
Unused Code introduced by
The call to printLogonPage() has too many arguments starting with true.

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...
45
        break; // End case 'Log Off'
46
47
    case 'gotuser': // Return from the getuser script
48
        Content::handleGotUser();
49
        break; // End case 'gotuser'
50
51
    case 'Go Back': // Return to the Main page
52
    case 'Proceed': // Proceed after 'User Changed' or Error page
53
    case 'Done with Two-Factor':
54
        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...
55
        break; // End case 'Go Back' / 'Proceed'
56
57
    case 'Cancel': // Cancel button on WAYF page - go to Google
58
        header('Location: https://www.google.com/');
59
        exit; // No further processing necessary
60
        break;
61
62
    case 'Get New Certificate':
63
        if (Util::verifySessionAndCall('CILogon\\Service\\Content::generateP12')) {
0 ignored issues
show
Documentation introduced by
'CILogon\\Service\\Content::generateP12' 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...
64
            printMainPage();
65
        }
66
        break; // End case 'Get New Certificate'
67
68
    case 'Manage Two-Factor':
69
        Util::verifySessionAndCall(
70
            '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...
71
        );
72
        break; // End case 'Manage Two-Factor'
73
74
    case 'Enable':   // Enable / Disable two-factor authentication
75
    case 'Disable':
76
    case 'Verify':   // Log in with Google Authenticator
77
    case 'Disable Two-Factor':
78
        $enable = !preg_match('/^Disable/', $submit);
79
        Util::verifySessionAndCall(
80
            '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...
81
            array($enable)
82
        );
83
        break; // End case 'Enable' / 'Disable'
84
85
    case 'I Lost My Phone':
86
        Util::verifySessionAndCall(
87
            '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...
88
        );
89
        break; // End case 'I Lost My Phone'
90
91
    case 'Enter': // Verify Google Authenticator one time password
92
        Util::verifySessionAndCall(
93
            '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...
94
        );
95
        break; // End case 'Enter'
96
97
    case 'EnterDuo': // Verify Duo Security login
98
        Util::verifySessionAndCall(
99
            '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...
100
        );
101
        break; // End case 'EnterDuo'
102
103
    case 'Show  Help ': // Toggle showing of help text on and off
104
    case 'Hide  Help ':
105
        Content::handleHelpButtonClicked();
106
        break; // End case 'Show Help' / 'Hide Help'
107
108
    default: // No submit button clicked nor PHP session submit variable set
109
        Content::handleNoSubmitButtonClicked();
110
        break; // End default case
111
} // End switch($submit)
112
113
// Util::$timeit->printTime('MAIN Program END...  ');
114