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 ( e0a7c0...a60ee2 )
by François
02:23
created

TestSocket::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
namespace SURFnet\VPN\Server\OpenVpn\Test;
19
20
use SURFnet\VPN\Server\OpenVpn\ManagementSocketInterface;
21
use SURFnet\VPN\Server\OpenVpn\ManagementSocketException;
22
23
/**
24
 * Abstraction to use the OpenVPN management interface using a socket
25
 * connection.
26
 */
27
class TestSocket implements ManagementSocketInterface
28
{
29
    /** @var string */
30
    private $callType;
31
32
    /** @var bool */
33
    private $connectFail;
34
35
    /** @var string */
36
    private $socketAddress;
37
38
    public function __construct($callType, $connectFail = false)
39
    {
40
        $this->callType = $callType;
41
        $this->connectFail = $connectFail;
42
        $this->socketAddress = null;
43
    }
44
45
    public function open($socketAddress, $timeOut = 5)
46
    {
47
        $this->socketAddress = $socketAddress;
48
        if ($this->connectFail) {
49
            throw new ManagementSocketException('unable to connect to socket');
50
        }
51
    }
52
53
    public function command($command)
54
    {
55
        if ('connections' === $this->callType) {
56 View Code Duplication
            if ('tcp://127.42.101.100: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...
57
                // send back the returnData as an array
58
                return explode("\n", file_get_contents(dirname(__DIR__).'/data/socket/openvpn_23_status_one_client.txt'));
59
            } else {
60
                return explode("\n", file_get_contents(dirname(__DIR__).'/data/socket/openvpn_23_status_no_clients.txt'));
61
            }
62 View Code Duplication
        } elseif ('kill' === $this->callType) {
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
            if ('tcp://127.42.101.100:11940' === $this->socketAddress) {
64
                return explode("\n", file_get_contents(dirname(__DIR__).'/data/socket/openvpn_23_kill_success.txt'));
65
            } else {
66
                return explode("\n", file_get_contents(dirname(__DIR__).'/data/socket/openvpn_23_kill_error.txt'));
67
            }
68
        }
69
    }
70
71
    public function close()
72
    {
73
        $this->socketAddress = null;
74
    }
75
}
76