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 ( 5dd421...7bf529 )
by François
02:29
created

InputValidation::ip6()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
rs 9.6666
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\InputValidationException;
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 InputValidationException('invalid "display_name"');
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 InputValidationException('invalid "common_name"');
46
        }
47
48
        return $commonName;
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public static function serverCommonName($serverCommonName)
55
    {
56
        if (1 !== preg_match('/^[a-zA-Z0-9-.]+$/', $serverCommonName)) {
57
            throw new InputValidationException('invalid "server_common_name"');
58
        }
59
60
        return $serverCommonName;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public static function profileId($profileId)
67
    {
68
        if (1 !== preg_match('/^[a-zA-Z0-9]+$/', $profileId)) {
69
            throw new InputValidationException('invalid "profile_id"');
70
        }
71
72
        return $profileId;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public static function instanceId($instanceId)
79
    {
80
        if (1 !== preg_match('/^[a-zA-Z0-9-.]+$/', $instanceId)) {
81
            throw new InputValidationException('invalid "instance_id"');
82
        }
83
84
        return $instanceId;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public static function languageCode($languageCode)
91
    {
92
        $supportedLanguages = ['en_US', 'nl_NL', 'de_DE', 'fr_FR'];
93
        if (!in_array($languageCode, $supportedLanguages)) {
94
            throw new InputValidationException('invalid "language_code"');
95
        }
96
97
        return $languageCode;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public static function totpSecret($totpSecret)
104
    {
105
        if (1 !== preg_match('/^[A-Z0-9]{16}$/', $totpSecret)) {
106
            throw new InputValidationException('invalid "totp_secret"');
107
        }
108
109
        return $totpSecret;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public static function totpKey($totpKey)
116
    {
117
        if (1 !== preg_match('/^[0-9]{6}$/', $totpKey)) {
118
            throw new InputValidationException('invalid "totp_key"');
119
        }
120
121
        return $totpKey;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public static function clientId($clientId)
128
    {
129
        if (1 !== preg_match('/^(?:[\x20-\x7E])+$/', $clientId)) {
130
            throw new InputValidationException('invalid "client_id"');
131
        }
132
133
        return $clientId;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public static function userName($userName)
140
    {
141
        if (1 !== preg_match('/^[a-zA-Z0-9-.@]+$/', $userName)) {
142
            throw new InputValidationException('invalid "user_name"');
143
        }
144
145
        return $userName;
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    public static function motdMessage($motdMessage)
152
    {
153
        // we accept everything...
154
        return $motdMessage;
155
    }
156
157
    /**
158
     * @return int
159
     */
160
    public static function dateTime($dateTime)
161
    {
162
        // try to parse first
163
        if (false === $unixTime = strtotime($dateTime)) {
164
            // if that fails, check if it is already unixTime
165
            if (is_numeric($dateTime)) {
166
                $unixTime = (int) $dateTime;
167
                if (0 <= $unixTime) {
168
                    return $unixTime;
169
                }
170
            }
171
172
            throw new InputValidationException('invalid "date_time"');
173
        }
174
175
        return $unixTime;
176
    }
177
178
    /**
179
     * @return string
180
     */
181 View Code Duplication
    public static function ipAddress($ipAddress)
0 ignored issues
show
Duplication introduced by
This method 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...
182
    {
183
        if (false === filter_var($ipAddress, FILTER_VALIDATE_IP)) {
184
            throw new InputValidationException('invalid "ip_address"');
185
        }
186
187
        // normalize the IP address (only makes a difference for IPv6)
188
        return inet_ntop(inet_pton($ipAddress));
189
    }
190
191
    /**
192
     * @return string
193
     */
194
    public static function vootToken($vootToken)
195
    {
196
        if (1 !== preg_match('/^[a-zA-Z0-9-]+$/', $vootToken)) {
197
            throw new InputValidationException('invalid "voot_token"');
198
        }
199
200
        return $vootToken;
201
    }
202
203
    /**
204
     * @return string
205
     */
206
    public static function ip4($ip4)
207
    {
208
        if (false === filter_var($ip4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
209
            throw new InputValidationException('invalid "ip4"');
210
        }
211
212
        return $ip4;
213
    }
214
215
    /**
216
     * @return string
217
     */
218 View Code Duplication
    public static function ip6($ip6)
0 ignored issues
show
Duplication introduced by
This method 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...
219
    {
220
        if (false === filter_var($ip6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
221
            throw new InputValidationException('invalid "ip6"');
222
        }
223
224
        // normalize the IPv6 address
225
        return inet_ntop(inet_pton($ip6));
226
    }
227
228
    /**
229
     * @return int
230
     */
231
    public static function connectedAt($connectedAt)
232
    {
233
        if (!is_numeric($connectedAt) || 0 > intval($connectedAt)) {
234
            throw new InputValidationException('invalid "connected_at"');
235
        }
236
237
        return intval($connectedAt);
238
    }
239
240
    /**
241
     * @return int
242
     */
243
    public static function disconnectedAt($disconnectedAt)
244
    {
245
        if (!is_numeric($disconnectedAt) || 0 > intval($disconnectedAt)) {
246
            throw new InputValidationException('invalid "disconnected_at"');
247
        }
248
249
        return intval($disconnectedAt);
250
    }
251
252
    /**
253
     * @return int
254
     */
255
    public static function bytesTransferred($bytesTransferred)
256
    {
257
        if (!is_numeric($bytesTransferred) || 0 > intval($bytesTransferred)) {
258
            throw new InputValidationException('invalid "bytes_transferred"');
259
        }
260
261
        return intval($bytesTransferred);
262
    }
263
264
    /**
265
     * @return string
266
     */
267
    public static function otpType($otpType)
268
    {
269
        if ('totp' !== $otpType) {
270
            throw new InputValidationException('invalid "otp_type"');
271
        }
272
273
        return $otpType;
274
    }
275
}
276