GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( eac42d...55bb68 )
by François
02:33
created

Controller::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 6
1
<?php
2
3
namespace fkooman\RemoteStorage\Http;
4
5
use fkooman\RemoteStorage\ApiModule;
6
use fkooman\RemoteStorage\Http\Exception\HttpException;
7
use fkooman\RemoteStorage\OAuth\BearerAuthentication;
8
use fkooman\RemoteStorage\OAuth\OAuthModule;
9
use fkooman\RemoteStorage\OAuth\TokenStorage;
10
use fkooman\RemoteStorage\RandomInterface;
11
use fkooman\RemoteStorage\RemoteStorage;
12
use fkooman\RemoteStorage\TplInterface;
13
use fkooman\RemoteStorage\UiModule;
14
use fkooman\RemoteStorage\WebfingerModule;
15
16
class Controller
17
{
18
    private $formAuth;
19
    private $bearerAuth;
20
    private $oauthModule;
21
    private $apiModule;
22
    private $uiModule;
23
    private $webfingerModule;
24
25
    public function __construct(TplInterface $tpl, SessionInterface $session, TokenStorage $tokenStorage, RandomInterface $random, RemoteStorage $remoteStorage, array $userPass)
26
    {
27
        $serverMode = 'development';
28
        $this->formAuth = new FormAuthentication($session, $tpl, $userPass);
29
        $this->bearerAuth = new BearerAuthentication($tokenStorage);
30
        $this->oauthModule = new OAuthModule($tpl, $random, $tokenStorage);
31
        $this->apiModule = new ApiModule($remoteStorage, $serverMode);
32
        $this->uiModule = new UiModule($remoteStorage, $tpl, $tokenStorage);
33
        $this->webfingerModule = new WebfingerModule($serverMode);
34
    }
35
36
    public function run(Request $request)
37
    {
38
        switch ($request->getRequestMethod()) {
39
            case 'GET':
40
                return $this->handleGet($request);
41
            case 'POST':
42
                return $this->handlePost($request);
43
            case 'PUT':
44
                $tokenInfo = $this->bearerAuth->requireAuth($request);
45
46
                return $this->apiModule->put($request, $tokenInfo);
47
            case 'DELETE':
48
                $tokenInfo = $this->bearerAuth->requireAuth($request);
49
50
                return $this->apiModule->delete($request, $tokenInfo);
51
            case 'OPTIONS':
52
                return $this->apiModule->options($request);
53
            case 'HEAD':
54
                $tokenInfo = $this->bearerAuth->requireAuth($request);
55
56
                return $this->apiModule->head($request, $tokenInfo);
57
            default:
58
                throw new HttpException('', 405);
59
       }
60
    }
61
62
    private function handleGet(Request $request)
63
    {
64
        switch ($request->getPathInfo()) {
65
            case '/.well-known/webfinger':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
66
67
                return $this->webfingerModule->getWebfinger($request);
68
            case '/_oauth/authorize':
69
                $userId = $this->formAuth->requireAuth($request);
70
                if ($userId instanceof Response) {
71
                    return $userId;
72
                }
73
74
                return $this->oauthModule->getAuthorize($request, $userId);
75
            case '/':
76
                $userId = $this->formAuth->optionalAuth($request);
77
78
                return $this->uiModule->getRootPage($request, $userId);
79
            case '/account':
80
                $userId = $this->formAuth->requireAuth($request);
81
                if ($userId instanceof Response) {
82
                    return $userId;
83
                }
84
85
                return $this->uiModule->getAccountPage($request, $userId);
86
            default:
87
                $tokenInfo = $this->bearerAuth->optionalAuth($request);
88
89
                return $this->apiModule->get($request, $tokenInfo);
0 ignored issues
show
Bug introduced by
It seems like $tokenInfo defined by $this->bearerAuth->optionalAuth($request) on line 87 can also be of type object<fkooman\RemoteStorage\OAuth\TokenInfo>; however, fkooman\RemoteStorage\ApiModule::get() does only seem to accept string|false, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
90
        }
91
    }
92
93
    private function handlePost(Request $request)
94
    {
95
        switch ($request->getPathInfo()) {
96
            case '/account':
97
                $userId = $this->formAuth->requireAuth($request);
98
99
                return $this->uiModule->postAccountPage($request, $userId);
100
101
            case '/_oauth/authorize':
102
                $userId = $this->formAuth->requireAuth($request);
103
104
                return $this->oauthModule->postAuthorize($request, $userId);
105
            case '/_auth/form/verify':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
106
107
                return $this->formAuth->verifyAuth($request);
108
            default:
109
                throw new HttpException('', 404);
110
        }
111
    }
112
}
113
114
//$request = new Request($_SERVER, $_GET, $_POST, file_get_contents('php://input'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
115