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 ( 932629...d7a7a8 )
by François
03:12
created

TestSocket::command()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 11

Duplication

Lines 13
Ratio 76.47 %

Importance

Changes 0
Metric Value
dl 13
loc 17
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 5
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\Tests;
20
21
use SURFnet\VPN\Server\OpenVpn\Exception\ManagementSocketException;
22
use SURFnet\VPN\Server\OpenVpn\ManagementSocketInterface;
23
24
/**
25
 * Abstraction to use the OpenVPN management interface using a socket
26
 * connection.
27
 */
28
class TestSocket implements ManagementSocketInterface
29
{
30
    /** @var bool */
31
    private $connectFail;
32
33
    /** @var string|null */
34
    private $socketAddress;
35
36
    public function __construct($connectFail = false)
37
    {
38
        $this->connectFail = $connectFail;
39
        $this->socketAddress = null;
40
    }
41
42
    /**
43
     * Open the socket.
44
     *
45
     * @param string $socketAddress the socket to connect to, e.g.:
46
     *                              "tcp://localhost:7505"
47
     * @param int    $timeOut       the amount of time to wait before
48
     *                              giving up on trying to connect
49
     *
50
     * @throws \SURFnet\VPN\Server\OpenVpn\Exception\ServerSocketException if the socket cannot be opened
51
     *                                                                     within timeout
52
     */
53
    public function open($socketAddress, $timeOut = 5)
54
    {
55
        $this->socketAddress = $socketAddress;
56
        if ($this->connectFail) {
57
            throw new ManagementSocketException('unable to connect to socket');
58
        }
59
    }
60
61
    /**
62
     * Send an OpenVPN command and get the response.
63
     *
64
     * @param string $command a OpenVPN management command and parameters
65
     *
66
     * @return array the response lines as array values
67
     *
68
     * @throws \SURFnet\VPN\Server\OpenVpn\Exception\ServerSocketException in case read/write fails or
69
     *                                                                     socket is not open
70
     */
71
    public function command($command)
72
    {
73
        if ('status 2' === $command) {
74 View Code Duplication
            if ('tcp://10.42.101.101:11940' === $this->socketAddress) {
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...
75
                // send back the returnData as an array
76
                return explode("\n", file_get_contents(__DIR__.'/data/socket/openvpn_23_status.txt'));
77
            } else {
78
                return explode("\n", file_get_contents(__DIR__.'/data/socket/openvpn_23_status_no_clients.txt'));
79
            }
80 View Code Duplication
        } elseif ('kill' === $command) {
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...
81
            if ('tcp://10.42.101.101:11940' === $this->socketAddress) {
82
                return explode("\n", file_get_contents(__DIR__.'/data/socket/openvpn_23_kill_success.txt'));
83
            } else {
84
                return explode("\n", file_get_contents(__DIR__.'/data/socket/openvpn_23_kill_error.txt'));
85
            }
86
        }
87
    }
88
89
    /**
90
     * Close the socket connection.
91
     *
92
     * @throws \SURFnet\VPN\Server\OpenVpn\Exception\ServerSocketException if socket is not open
93
     */
94
    public function close()
95
    {
96
        $this->socketAddress = null;
97
    }
98
}
99