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

oauth/index.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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...
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
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
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