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 ( f2c293...1d2960 )
by François
02:03
created

InputValidation::totpKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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
19
namespace SURFnet\VPN\Common\Http;
20
21
use SURFnet\VPN\Common\Http\Exception\HttpException;
22
23
class InputValidation
24
{
25
    /**
26
     * @return string
27
     */
28
    public static function displayName($displayName)
29
    {
30
        $displayName = filter_var($displayName, FILTER_UNSAFE_RAW, FILTER_FLAG_STRIP_LOW);
31
32
        if (0 === mb_strlen($displayName)) {
33
            throw new HttpException('invalid "display_name"', 400);
34
        }
35
36
        return $displayName;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public static function commonName($commonName)
43
    {
44
        if (1 !== preg_match('/^[a-fA-F0-9]{32}$/', $commonName)) {
45
            throw new HttpException('invalid "common_name"', 400);
46
        }
47
48
        return $commonName;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public static function profileId($profileId)
55
    {
56
        if (1 !== preg_match('/^[a-zA-Z0-9]+$/', $profileId)) {
57
            throw new HttpException('invalid "profile_id"', 400);
58
        }
59
60
        return $profileId;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public static function languageCode($languageCode)
67
    {
68
        $supportedLanguages = ['en_US', 'nl_NL', 'de_DE', 'fr_FR'];
69
        if (!in_array($setLanguage, $supportedLanguages)) {
0 ignored issues
show
Bug introduced by
The variable $setLanguage does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
70
            throw new HttpException('invalid "language_code"', 400);
71
        }
72
73
        return $languageCode;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public static function totpSecret($totpSecret)
80
    {
81
        if (1 !== preg_match('/^[A-Z0-9]{16}$/', $totpSecret)) {
82
            throw new HttpException('invalid "totp_secret"', 400);
83
        }
84
85
        return $totpSecret;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public static function totpKey($totpKey)
92
    {
93
        if (1 !== preg_match('/^[0-9]{6}$/', $totpKey)) {
94
            throw new HttpException('invalid "totp_key"', 400);
95
        }
96
97
        return $totpKey;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public static function clientId($clientId)
104
    {
105
        if (1 !== preg_match('/^(?:[\x20-\x7E])+$/', $clientId)) {
106
            throw new HttpException('invalid "client_id"', 400);
107
        }
108
109
        return $clientId;
110
    }
111
}
112