index.php ➔ oauthCallback()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 3
dl 0
loc 25
rs 9.2088
c 0
b 0
f 0
1
<?php
2
require_once('vendor/autoload.php');
3
require_once('../Autoload.php');
4
5
if($_SERVER['REQUEST_URI'][0] == '/' && $_SERVER['REQUEST_URI'][1] == '/')
6
{
7
    $_SERVER['REQUEST_URI'] = substr($_SERVER['REQUEST_URI'], 1);
8
}
9
10
$app = new \Slim\App();
11
$app->get('/callbacks/{host}', 'oauthCallback');
12
13
function oauthCallback($request, $response, $args)
14
{
15
    $host = $args['host'];
16
    $auth = \Flipside\AuthProvider::getInstance();
17
    $provider = $auth->getSuplementalProviderByHost($host);
18
    if($provider === false)
19
    {
20
        return $response->withStatus(404);
21
    }
22
    $res = $provider->authenticate($request->getQueryParams(), $currentUser);
0 ignored issues
show
Bug introduced by
The variable $currentUser does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
23
    switch($res)
24
    {
25
        case \Flipside\Auth\Authenticator::SUCCESS:
26
            $response = $response->withHeader('Location', '/');
27
            break;
28
        default:
29
        case \Flipside\Auth\Authenticator::LOGIN_FAILED:
0 ignored issues
show
Unused Code introduced by
case \Flipside\Auth\Auth...?failed=1'); break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
30
            $response = $response->withHeader('Location', '/login.php?failed=1');
31
            break;
32
        case \Flipside\Auth\Authenticator::ALREADY_PRESENT:
33
            $response = $response->withHeader('Location', '/user_exists.php?src='.$host.'&uid='.$currentUser->getUID());
34
            break;
35
    }
36
    return $response->withStatus(302);
37
}
38
39
$app->run();
40
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
41