Completed
Pull Request — develop (#48)
by Patrick
01:48
created

index.php ➔ oauthCallback()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 25
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 19
nc 3
nop 3
dl 0
loc 25
rs 8.439
c 0
b 0
f 0
1
<?php
2
require_once('vendor/autoload.php');
3
require_once('class.AuthProvider.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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
{
15
    $host = $args['host'];
16
    $auth = AuthProvider::getInstance();
17
    $provider = $auth->getSuplementalProviderByHost($host);
18
    if($provider === false)
19
    {
20
        return $response->withStatus(404);
21
    }
22
    $res = $provider->authenticate($app->request->get(), $currentUser);
0 ignored issues
show
Bug introduced by
The variable $app 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...
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 \Auth\Authenticator::SUCCESS:
26
            $response = $response->withHeader('Location', '/');
27
            break;
28
        default:
29
        case \Auth\Authenticator::LOGIN_FAILED:
0 ignored issues
show
Unused Code introduced by
case \Auth\Authenticator...?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 \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