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 ( 71cc31...7de261 )
by François
04:22
created

InputValidation::poolId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
namespace SURFnet\VPN\Server;
19
20
use SURFnet\VPN\Server\Exception\InputValidationException;
21
22
class InputValidation
23
{
24
    public static function instanceId($instanceId)
25
    {
26
        if (0 === preg_match('/^[a-zA-Z0-9-\.]+$/', $instanceId)) {
27
            throw new InputValidationException('invalid instanceId pattern');
28
        }
29
        // MUST not be '..'
30
        if ('..' === $instanceId) {
31
            throw new InputValidationException('invalid instanceId pattern, cannot be ".."');
32
        }
33
34
        return $instanceId;
35
    }
36
37
    public static function poolId($poolId)
38
    {
39
        if (0 === preg_match('/^[a-zA-Z0-9]{2,}$/', $poolId)) {
40
            throw new InputValidationException('invalid poolId pattern');
41
        }
42
43
        return $poolId;
44
    }
45
46
    public static function userName($userName)
47
    {
48
        if ('totp' !== $userName) {
49
            throw new InputValidationException('invalid userName');
50
        }
51
52
        return $userName;
53
    }
54
55
    public static function commonName($commonName)
56
    {
57
        // the commonName consists of a userId and a configName seperated by an
58
        // underscore, needs to be at least of length 3
59
        if (0 === preg_match('/^[a-zA-Z0-9-_.@]{3,}$/', $commonName)) {
60
            throw new InputValidationException('invalid commonName pattern');
61
        }
62
        if (false === strpos($commonName, '_')) {
63
            throw new InputValidationException('invalid commonName pattern, requires underscore');
64
        }
65
        if (strlen($commonName) - 1 === strrpos($commonName, '_')) {
66
            throw new InputValidationException('invalid commonName pattern, cannot end with underscore');
67
        }
68
69
        return $commonName;
70
    }
71
72
    public static function otpKey($otpKey)
73
    {
74
        // the otpKey consists of 6 digits
75
        if (0 === preg_match('/^[0-9]{6}$/', $otpKey)) {
76
            throw new InputValidationException('invalid otpKey pattern');
77
        }
78
79
        return $otpKey;
80
    }
81
}
82