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 ( 747ec8...65058f )
by François
02:33
created

housekeeping.php ➔ cleanupOtp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
#!/usr/bin/php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 1.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
<?php
3
/**
4
 *  Copyright (C) 2016 SURFnet.
5
 *
6
 *  This program is free software: you can redistribute it and/or modify
7
 *  it under the terms of the GNU Affero General Public License as
8
 *  published by the Free Software Foundation, either version 3 of the
9
 *  License, or (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU Affero General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU Affero General Public License
17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
require_once sprintf('%s/vendor/autoload.php', dirname(__DIR__));
20
21
use SURFnet\VPN\Server\OtpLog;
22
23 View Code Duplication
function showHelp(array $argv)
0 ignored issues
show
Best Practice introduced by
The function showHelp() has been defined more than once; this definition is ignored, only the first definition in bin/generate-firewall.php (L25-36) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    return implode(
26
        PHP_EOL,
27
        [
28
            sprintf('SYNTAX: %s [--instance domain.tld]', $argv[0]),
29
            '',
30
            '--instance domain.tld      the instance to housekeep',
31
            '',
32
        ]
33
    );
34
}
35
36
try {
37
    $instanceId = null;
38
39 View Code Duplication
    for ($i = 0; $i < $argc; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
        if ('--help' == $argv[$i] || '-h' === $argv[$i]) {
41
            echo showHelp($argv);
42
            exit(0);
43
        }
44
45
        if ('--instance' === $argv[$i] || '-i' === $argv[$i]) {
46
            if (array_key_exists($i + 1, $argv)) {
47
                $instanceId = $argv[$i + 1];
48
                ++$i;
49
            }
50
        }
51
    }
52
53
    if (is_null($instanceId)) {
54
        throw new RuntimeException('instance must be specified, see --help');
55
    }
56
57
    $vpnDataDir = sprintf('%s/openvpn-data/%s', dirname(__DIR__), $instanceId);
58
    $db = new PDO(sprintf('sqlite://%s/otp.sqlite', $vpnDataDir));
59
    $otpLog = new OtpLog($db);
60
    // remove all OTP key entries that are older than 5 minutes
61
    $otpLog->housekeeping(strtotime('now -5 minutes'));
62
} catch (Exception $e) {
63
    echo sprintf('ERROR: %s', $e->getMessage()).PHP_EOL;
64
    exit(1);
65
}
66