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.

YubiKey::verify()   B
last analyzed

Complexity

Conditions 5
Paths 11

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 23
rs 8.5906
cc 5
eloc 12
nc 11
nop 3
1
<?php
2
3
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Server;
11
12
use fkooman\YubiTwee\CurlMultiHttpClient;
13
use fkooman\YubiTwee\Exception\YubiTweeException;
14
use fkooman\YubiTwee\Validator;
15
use SURFnet\VPN\Server\Exception\YubiKeyException;
16
17
class YubiKey
18
{
19
    public function verify($userId, $yubiKeyOtp, $yubiKeyId = null)
0 ignored issues
show
Unused Code introduced by
The parameter $userId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
    {
21
        try {
22
            $validator = new Validator(new CurlMultiHttpClient());
23
            $response = $validator->verify($yubiKeyOtp);
24
25
            if ($response->success()) {
26
                if (!is_null($yubiKeyId)) {
27
                    // the yubiKeyId MUST match the Id from the validation
28
                    // response
29
                    if ($yubiKeyId !== $response->id()) {
30
                        throw new YubiKeyException('user not bound to this YubiKey ID');
31
                    }
32
                }
33
34
                return $response->id();
35
            }
36
37
            throw new YubiKeyException(sprintf('YubiKey OTP is not valid: %s', $response->status()));
38
        } catch (YubiTweeException $e) {
39
            throw new YubiKeyException(sprintf('YubiKey OTP validation failed: %s', $e->getMessage()));
40
        }
41
    }
42
}
43