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 ( 35efb6...ee0423 )
by François
02:44
created

OpenVpnModule   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 23.53 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 2
c 4
b 0
f 0
lcom 1
cbo 7
dl 8
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A init() 8 23 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Copyright 2016 François Kooman <[email protected]>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace fkooman\VPN\Server\Api;
19
20
use fkooman\Http\Request;
21
use fkooman\Rest\Service;
22
use fkooman\Rest\ServiceModuleInterface;
23
use fkooman\VPN\Server\InputValidation;
24
use fkooman\Rest\Plugin\Authentication\Bearer\TokenInfo;
25
use fkooman\VPN\Server\OpenVpn\ServerManager;
26
use fkooman\VPN\Server\ApiResponse;
27
28
class OpenVpnModule implements ServiceModuleInterface
29
{
30
    /** @var ServerManager */
31
    private $serverManager;
32
33
    public function __construct(ServerManager $serverManager)
34
    {
35
        $this->serverManager = $serverManager;
36
    }
37
38
    public function init(Service $service)
39
    {
40
        $service->get(
41
            '/openvpn/connections',
42
            function (Request $request, TokenInfo $tokenInfo) {
43
                $tokenInfo->getScope()->requireScope(['admin']);
44
45
                return new ApiResponse('connections', $this->serverManager->connections());
46
            }
47
        );
48
49
        $service->post(
50
            '/openvpn/kill',
51 View Code Duplication
            function (Request $request, TokenInfo $tokenInfo) {
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...
52
                $tokenInfo->getScope()->requireScope(['admin', 'portal']);
53
54
                $commonName = $request->getPostParameter('common_name');
55
                InputValidation::commonName($commonName);
56
57
                return new ApiResponse('ok', $this->serverManager->kill($commonName));
58
            }
59
        );
60
    }
61
}
62