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 ( 71cc31...7de261 )
by François
04:22
created

TestHttpClient::get()   C

Complexity

Conditions 11
Paths 11

Size

Total Lines 49
Code Lines 33

Duplication

Lines 18
Ratio 36.73 %

Importance

Changes 0
Metric Value
cc 11
eloc 33
nc 11
nop 1
dl 18
loc 49
rs 5.2653
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
namespace SURFnet\VPN\Server\Test;
19
20
use SURFnet\VPN\Common\HttpClient\HttpClientInterface;
21
use RuntimeException;
22
use SURFnet\VPN\Server\PoolConfig;
23
24
class TestHttpClient implements HttpClientInterface
25
{
26
    public function get($requestUri)
27
    {
28
        switch ($requestUri) {
29
            case 'serverClient/has_otp_secret?user_id=foo':
30
                return self::wrap('has_otp_secret', true);
31
            case 'serverClient/has_otp_secret?user_id=bar':
32
                return self::wrap('has_otp_secret', false);
33
34
            case 'connectionServerClient/is_disabled_user?user_id=foo':
35
                return self::wrap('is_disabled_user', false);
36
            case 'connectionServerClient/is_disabled_user?user_id=bar':
37
                return self::wrap('is_disabled_user', true);
38
            case 'connectionServerClient/is_disabled_common_name?common_name=foo_bar':
39
                return self::wrap('is_disabled_common_name', false);
40
            case 'connectionServerClient/is_disabled_common_name?common_name=foo_baz':
41
                return self::wrap('is_disabled_common_name', true);
42
            case 'connectionServerClient/server_pool?pool_id=internet':
43
                $poolConfig = new PoolConfig([]);
44
45
                return self::wrap('server_pool', $poolConfig->v());
46 View Code Duplication
            case 'connectionServerClient/server_pool?pool_id=acl':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
47
                $poolConfig = new PoolConfig(
48
                    [
49
                        'enableAcl' => true,
50
                        'aclGroupList' => ['all'],
51
                    ]
52
                );
53
54
                return self::wrap('server_pool', $poolConfig->v());
55 View Code Duplication
            case 'connectionServerClient/server_pool?pool_id=acl2':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
56
                $poolConfig = new PoolConfig(
57
                    [
58
                        'enableAcl' => true,
59
                        'aclGroupList' => ['students'],
60
                    ]
61
                );
62
63
                return self::wrap('server_pool', $poolConfig->v());
64
            case 'connectionServerClient/user_groups?user_id=foo':
65
                return self::wrap(
66
                    'user_groups',
67
                    [
68
                        ['id' => 'all', 'displayName' => 'All'],
69
                    ]
70
                );
71
            default:
72
                throw new RuntimeException(sprintf('unexpected requestUri "%s"', $requestUri));
73
        }
74
    }
75
76
    public function post($requestUri, array $postData)
77
    {
78
        switch ($requestUri) {
79
            case 'serverClient/verify_otp_key':
80
                if ('123456' === $postData['otp_key']) {
81
                    return self::wrap('verify_otp_key', true);
82
                }
83
84
                return self::wrap('verify_otp_key', false);
85
            case 'connectionServerClient/log_connect':
86
                return self::wrap('log_connect', true);
87
            case 'connectionServerClient/log_disconnect':
88
                return self::wrap('log_disconnect', true);
89
            default:
90
                throw new RuntimeException(sprintf('unexpected requestUri "%s"', $requestUri));
91
        }
92
    }
93
94
    private static function wrap($key, $response)
95
    {
96
        return [
97
            'data' => [
98
                $key => $response,
99
            ],
100
        ];
101
    }
102
}
103