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 ( bca83a...1ac405 )
by François
03:36
created

LogModule::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace fkooman\VPN\Server\Log;
4
5
use fkooman\Http\Request;
6
use fkooman\Rest\Service;
7
use fkooman\Rest\ServiceModuleInterface;
8
use fkooman\VPN\Server\Utils;
9
use fkooman\Http\Exception\BadRequestException;
10
use fkooman\IO\IO;
11
use fkooman\Http\JsonResponse;
12
13
class LogModule implements ServiceModuleInterface
14
{
15
    /** @var ConnectionLog */
16
    private $connectionLog;
17
18
    /** @var fkooman\IO\IO */
19
    private $io;
20
    public function __construct(ConnectionLog $connectionLog, IO $io = null)
21
    {
22
        $this->connectionLog = $connectionLog;
23
        if (is_null($io)) {
24
            $io = new IO();
25
        }
26
        $this->io = $io;
0 ignored issues
show
Documentation Bug introduced by
It seems like $io of type object<fkooman\IO\IO> is incompatible with the declared type object<fkooman\VPN\Server\Log\fkooman\IO\IO> of property $io.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
    }
28
29
    public function init(Service $service)
30
    {
31
        $service->get(
32
            '/log/history',
33
            function (Request $request) {
34
                $showDate = $request->getUrl()->getQueryParameter('showDate');
35
                if (is_null($showDate)) {
36
                    $showDate = date('Y-m-d', $this->io->getTime());
37
                }
38
                if (!is_string($showDate)) {
39
                    $showDate = date('Y-m-d', $this->io->getTime());
40
                }
41
                Utils::validateDate($showDate);
42
                $showDateUnix = strtotime($showDate);
43
44
                $minDate = strtotime('today -31 days');
45
                $maxDate = strtotime('tomorrow');
46
47
                if ($showDateUnix < $minDate || $showDateUnix >= $maxDate) {
48
                    throw new BadRequestException('invalid date range');
49
                }
50
51
                $showDateUnixMin = strtotime('today', $showDateUnix);
52
                $showDateUnixMax = strtotime('tomorrow', $showDateUnix);
53
54
                $response = new JsonResponse();
55
                if (is_null($this->connectionLog)) {
56
                    $responseData = array(
57
                        'ok' => false,
58
                        'error' => 'unable to connect to log database',
59
                    );
60
                } else {
61
                    $responseData = array(
62
                        'ok' => true,
63
                        'history' => $this->connectionLog->getConnectionHistory($showDateUnixMin, $showDateUnixMax),
64
                    );
65
                }
66
                $response->setBody($responseData);
67
68
                return $response;
69
            }
70
        );
71
    }
72
}
73