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 ( 737b3f...ca0726 )
by François
05:21
created

ServerService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6667
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
/**
4
 * Copyright 2015 François Kooman <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
namespace fkooman\VPN\Server;
19
20
use fkooman\Rest\Service;
21
use fkooman\Http\JsonResponse;
22
use fkooman\Http\Request;
23
use fkooman\Http\Exception\BadRequestException;
24
25
/**
26
 * This class registers and handles routes.
27
 */
28
class ServerService extends Service
29
{
30
    /** @var ServerManager */
31
    private $serverManager;
32
33
    /** @var CcdHandler */
34
    private $ccdHandler;
35
36
    /** @var CrlFetcher */
37
    private $crlFetcher;
38
39
    public function __construct(ServerManager $serverManager, CcdHandler $ccdHandler, CrlFetcher $crlFetcher)
40
    {
41
        $this->serverManager = $serverManager;
42
        $this->ccdHandler = $ccdHandler;
43
        $this->crlFetcher = $crlFetcher;
44
45
        parent::__construct();
46
        $this->registerRoutes();
47
    }
48
49
    private function registerRoutes()
50
    {
51
        $this->get(
52
            '/status',
53
            function (Request $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
54
                $response = new JsonResponse();
55
                $response->setBody($this->serverManager->status());
56
57
                return $response;
58
            }
59
        );
60
61
        $this->get(
62
            '/load-stats',
63
            function (Request $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
64
                $response = new JsonResponse();
65
                $response->setBody($this->serverManager->loadStats());
66
67
                return $response;
68
            }
69
        );
70
71
        $this->get(
72
            '/version',
73
            function (Request $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
74
                $response = new JsonResponse();
75
                $response->setBody($this->serverManager->version());
76
77
                return $response;
78
            }
79
        );
80
81
        $this->post(
82
            '/kill',
83 View Code Duplication
            function (Request $request) {
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...
84
                $commonName = $request->getPostParameter('common_name');
85
                Utils::validateCommonName($commonName);
86
87
                $response = new JsonResponse();
88
                $response->setBody($this->serverManager->kill($commonName));
89
90
                return $response;
91
            }
92
        );
93
94
        $this->post(
95
            '/ccd/disable',
96 View Code Duplication
            function (Request $request) {
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...
97
                $commonName = $request->getPostParameter('common_name');
98
                if (is_null($commonName)) {
99
                    throw new BadRequestException('missing common_name');
100
                }
101
                Utils::validateCommonName($commonName);
102
103
                $response = new JsonResponse();
104
                $response->setBody(
105
                    array(
106
                        'ok' => $this->ccdHandler->disableCommonName($commonName),
107
                    )
108
                );
109
110
                return $response;
111
            }
112
        );
113
114
        $this->delete(
115
            '/ccd/disable',
116 View Code Duplication
            function (Request $request) {
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...
117
                $commonName = $request->getUrl()->getQueryParameter('common_name');
118
                Utils::validateCommonName($commonName);
119
120
                $response = new JsonResponse();
121
                $response->setBody(
122
                    array(
123
                        'ok' => $this->ccdHandler->enableCommonName($commonName),
124
                    )
125
                );
126
127
                return $response;
128
            }
129
        );
130
131
        $this->get(
132
            '/ccd/disable',
133 View Code Duplication
            function (Request $request) {
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...
134
                // we typically deal with CNs, not user IDs, but the part of 
135
                // the CN before the first '_' is considered the user ID
136
                $userId = $request->getUrl()->getQueryParameter('user_id');
137
                if (!is_null($userId)) {
138
                    Utils::validateUserId($userId);
139
                }
140
141
                $response = new JsonResponse();
142
                $response->setBody(
143
                    array(
144
                        'ok' => true,
145
                        'disabled' => $this->ccdHandler->getDisabledCommonNames($userId),
146
                    )
147
                );
148
149
                return $response;
150
            }
151
        );
152
153
        $this->post(
154
            '/crl/fetch',
155
            function (Request $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
156
                $response = new JsonResponse();
157
                $response->setBody($this->crlFetcher->fetch());
158
159
                return $response;
160
            }
161
        );
162
    }
163
}
164