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 ( 00c2b4...ff24ee )
by François
02:33
created

InputValidation::vootToken()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 3
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Copyright 2016 François Kooman <[email protected]>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace fkooman\VPN\Server;
19
20
use fkooman\Http\Exception\BadRequestException;
21
22
class InputValidation
23
{
24
    const COMMON_NAME_PATTERN = '/^[a-zA-Z0-9-_.@]+$/';
25
    const USER_ID_PATTERN = '/^[a-zA-Z0-9-_.@]+$/';
26
    const DATE_PATTERN = '/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/';
27
    const OTP_KEY_PATTERN = '/^[0-9]{6}$/';
28
    const OTP_SECRET_PATTERN = '/^[A-Z0-9]{16}$/';
29
30
    public static function commonName($commonName)
31
    {
32
        if (0 === preg_match(self::COMMON_NAME_PATTERN, $commonName)) {
33
            throw new BadRequestException('invalid value for "common_name"');
34
        }
35
        if ('..' === $commonName) {
36
            throw new BadRequestException('"common_name" cannot be ".."');
37
        }
38
    }
39
40
    public static function userId($userId)
41
    {
42
        if (0 === preg_match(self::USER_ID_PATTERN, $userId)) {
43
            throw new BadRequestException('invalid value for "user_id"');
44
        }
45
        if ('..' === $userId) {
46
            throw new BadRequestException('"user_id" cannot be ".."');
47
        }
48
    }
49
50
    public static function date($date)
51
    {
52
        if (0 === preg_match(self::DATE_PATTERN, $date)) {
53
            throw new BadRequestException('invalid value for "date"');
54
        }
55
    }
56
57
    public static function disable($disable)
58
    {
59
        if (!is_bool($disable)) {
60
            throw new BadRequestException('"disable" must be boolean');
61
        }
62
    }
63
64
    public static function otpKey($otpKey)
65
    {
66
        if (0 === preg_match(self::OTP_KEY_PATTERN, $otpKey)) {
67
            throw new BadRequestException('invalid OTP key format');
68
        }
69
    }
70
71
    public static function otpSecret($otpSecret)
72
    {
73
        if (0 === preg_match(self::OTP_SECRET_PATTERN, $otpSecret)) {
74
            throw new BadRequestException('invalid OTP secret format');
75
        }
76
    }
77
78
    public static function vootToken($vootToken)
79
    {
80
        // XXX OAuth bearer tokens have a defined syntax!
81
        if (!is_string($vootToken) || 0 >= strlen($vootToken)) {
82
            throw new BadRequestException('voot token must be non-empty string');
83
        }
84
    }
85
86
    public static function ipAddress($ipAddress)
87
    {
88
        if (false === filter_var($ipAddress, FILTER_VALIDATE_IP)) {
89
            throw new BadRequestException('invalid IP address');
90
        }
91
    }
92
}
93