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 ( 6cbd46...4c991e )
by François
04:09
created

InfoModule::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 21
rs 9.3142
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
namespace fkooman\VPN\Server\Info;
4
5
use fkooman\Http\Request;
6
use fkooman\Rest\Service;
7
use fkooman\Rest\ServiceModuleInterface;
8
use fkooman\Http\JsonResponse;
9
use fkooman\Http\Exception\ForbiddenException;
10
use fkooman\Rest\Plugin\Authentication\Bearer\TokenInfo;
11
12
class InfoModule implements ServiceModuleInterface
13
{
14
    /** @var array */
15
    private $v4;
16
17
    /** @var array */
18
    private $v6;
19
20
    public function __construct(array $v4, array $v6)
21
    {
22
        $this->v4 = $v4;
23
        $this->v6 = $v6;
24
    }
25
26
    public function init(Service $service)
27
    {
28
        $service->get(
29
            '/info',
30
            function (Request $request, TokenInfo $tokenInfo) {
31
                self::requireScope($tokenInfo, 'info_get');
32
33
                $response = new JsonResponse();
34
                $response->setBody(
35
                    [
36
                        'ip' => [
37
                            'v4' => $this->v4,
38
                            'v6' => $this->v6,
39
                        ],
40
                    ]
41
                );
42
43
                return $response;
44
            }
45
        );
46
    }
47
48
    private static function requireScope(TokenInfo $tokenInfo, $requiredScope)
49
    {
50
        if (!$tokenInfo->getScope()->hasScope($requiredScope)) {
51
            throw new ForbiddenException('insufficient_scope', sprintf('"%s" scope required', $requiredScope));
52
        }
53
    }
54
}
55