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 ( ad44e8...fee13a )
by François
03:34
created

SystemMessagesModule::init()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 20

Duplication

Lines 14
Ratio 34.15 %

Importance

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