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 ( f15ffd...f83d28 )
by François
02:15
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 otpSecret($otpSecret)
104
    {
105
        if (1 !== preg_match('/^[A-Z0-9]{16}$/', $otpSecret)) {
106
            throw new InputValidationException('invalid "otp_secret"');
107
        }
108
109
        return $otpSecret;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public static function otpKey($otpKey)
116
    {
117
        if (1 !== preg_match('/^[0-9]{6}$/', $otpKey)) {
118
            throw new InputValidationException('invalid "otp_key"');
119
        }
120
121
        return $otpKey;
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 userId($userId)
140
    {
141
        if (1 !== preg_match('/^[a-zA-Z0-9-.@]+$/', $userId)) {
142
            throw new InputValidationException('invalid "user_id"');
143
        }
144
145
        return $userId;
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
            $unixTime = intval($dateTime);
166
            if (0 <= $unixTime) {
167
                return $unixTime;
168
            }
169
170
            throw new InputValidationException('invalid "date_time"');
171
        }
172
173
        return $unixTime;
174
    }
175
176
    /**
177
     * @return string
178
     */
179 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...
180
    {
181
        if (false === filter_var($ipAddress, FILTER_VALIDATE_IP)) {
182
            throw new InputValidationException('invalid "ip_address"');
183
        }
184
185
        // normalize the IP address (only makes a difference for IPv6)
186
        return inet_ntop(inet_pton($ipAddress));
187
    }
188
189
    /**
190
     * @return string
191
     */
192
    public static function vootToken($vootToken)
193
    {
194
        if (1 !== preg_match('/^[a-zA-Z0-9-]+$/', $vootToken)) {
195
            throw new InputValidationException('invalid "voot_token"');
196
        }
197
198
        return $vootToken;
199
    }
200
201
    /**
202
     * @return string
203
     */
204
    public static function ip4($ip4)
205
    {
206
        if (false === filter_var($ip4, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
207
            throw new InputValidationException('invalid "ip4"');
208
        }
209
210
        return $ip4;
211
    }
212
213
    /**
214
     * @return string
215
     */
216 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...
217
    {
218
        if (false === filter_var($ip6, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
219
            throw new InputValidationException('invalid "ip6"');
220
        }
221
222
        // normalize the IPv6 address
223
        return inet_ntop(inet_pton($ip6));
224
    }
225
226
    /**
227
     * @return int
228
     */
229
    public static function connectedAt($connectedAt)
230
    {
231
        if (!is_numeric($connectedAt) || 0 > intval($connectedAt)) {
232
            throw new InputValidationException('invalid "connected_at"');
233
        }
234
235
        return intval($connectedAt);
236
    }
237
238
    /**
239
     * @return int
240
     */
241
    public static function disconnectedAt($disconnectedAt)
242
    {
243
        if (!is_numeric($disconnectedAt) || 0 > intval($disconnectedAt)) {
244
            throw new InputValidationException('invalid "disconnected_at"');
245
        }
246
247
        return intval($disconnectedAt);
248
    }
249
250
    /**
251
     * @return int
252
     */
253
    public static function bytesTransferred($bytesTransferred)
254
    {
255
        if (!is_numeric($bytesTransferred) || 0 > intval($bytesTransferred)) {
256
            throw new InputValidationException('invalid "bytes_transferred"');
257
        }
258
259
        return intval($bytesTransferred);
260
    }
261
262
    /**
263
     * @return string
264
     */
265
    public static function otpType($otpType)
266
    {
267
        if ('totp' !== $otpType) {
268
            throw new InputValidationException('invalid "otp_type"');
269
        }
270
271
        return $otpType;
272
    }
273
}
274