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   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 0 17 2
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