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.

StatsModule::init()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 1
nop 1
1
<?php
2
3
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Server\Api;
11
12
use RuntimeException;
13
use SURFnet\VPN\Common\FileIO;
14
use SURFnet\VPN\Common\Http\ApiResponse;
15
use SURFnet\VPN\Common\Http\AuthUtils;
16
use SURFnet\VPN\Common\Http\Request;
17
use SURFnet\VPN\Common\Http\Service;
18
use SURFnet\VPN\Common\Http\ServiceModuleInterface;
19
20
class StatsModule implements ServiceModuleInterface
21
{
22
    /** @var string */
23
    private $dataDir;
24
25
    public function __construct($dataDir)
26
    {
27
        $this->dataDir = $dataDir;
28
    }
29
30
    public function init(Service $service)
31
    {
32
        $service->get(
33
            '/stats',
34
            function (Request $request, array $hookData) {
35
                AuthUtils::requireUser($hookData, ['vpn-admin-portal']);
36
                $statsFile = sprintf('%s/stats.json', $this->dataDir);
37
38
                try {
39
                    return new ApiResponse('stats', FileIO::readJsonFile($statsFile));
40
                } catch (RuntimeException $e) {
41
                    // no stats file available yet
42
                    return new ApiResponse('stats', false);
43
                }
44
            }
45
        );
46
    }
47
}
48