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.

SystemMessagesModule::init()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 20

Duplication

Lines 27
Ratio 65.85 %

Importance

Changes 0
Metric Value
dl 27
loc 41
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 20
nc 1
nop 1
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\Api;
11
12
use SURFnet\VPN\Common\Http\ApiResponse;
13
use SURFnet\VPN\Common\Http\AuthUtils;
14
use SURFnet\VPN\Common\Http\InputValidation;
15
use SURFnet\VPN\Common\Http\Request;
16
use SURFnet\VPN\Common\Http\Service;
17
use SURFnet\VPN\Common\Http\ServiceModuleInterface;
18
use SURFnet\VPN\Server\Storage;
19
20
class SystemMessagesModule implements ServiceModuleInterface
21
{
22
    /** @var \SURFnet\VPN\Server\Storage */
23
    private $storage;
24
25
    public function __construct(Storage $storage)
26
    {
27
        $this->storage = $storage;
28
    }
29
30
    public function init(Service $service)
31
    {
32
        $service->get(
33
            '/system_messages',
34 View Code Duplication
            function (Request $request, array $hookData) {
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...
35
                AuthUtils::requireUser($hookData, ['vpn-admin-portal', 'vpn-user-portal']);
36
37
                $type = InputValidation::messageType($request->getQueryParameter('message_type'));
38
39
                return new ApiResponse('system_messages', $this->storage->systemMessages($type));
40
            }
41
        );
42
43
        $service->post(
44
            '/add_system_message',
45 View Code Duplication
            function (Request $request, array $hookData) {
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...
46
                AuthUtils::requireUser($hookData, ['vpn-admin-portal']);
47
48
                $type = InputValidation::messageType($request->getPostParameter('message_type'));
49
50
                // we do NOT sanitize or verify message as *everything* is
51
                // allowed! It will never be used as-is for showing in the
52
                // browser, as the user portal will escape it before showing
53
                // and the apps MUST interprete it as "text/plain".
54
                $message = $request->getPostParameter('message_body');
55
56
                return new ApiResponse('add_system_message', $this->storage->addSystemMessage($type, $message));
57
            }
58
        );
59
60
        $service->post(
61
            '/delete_system_message',
62 View Code Duplication
            function (Request $request, array $hookData) {
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...
63
                AuthUtils::requireUser($hookData, ['vpn-admin-portal']);
64
65
                $messageId = InputValidation::messageId($request->getPostParameter('message_id'));
66
67
                return new ApiResponse('delete_system_message', $this->storage->deleteSystemMessage($messageId));
68
            }
69
        );
70
    }
71
}
72