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.

TlsAuth::execOpenVpn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
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;
11
12
use RuntimeException;
13
use SURFnet\VPN\Common\FileIO;
14
15
class TlsAuth
16
{
17
    /** @var string */
18
    private $dataDir;
19
20
    public function __construct($dataDir)
21
    {
22
        $this->dataDir = $dataDir;
23
    }
24
25
    public function init()
26
    {
27
        $taFile = sprintf('%s/ta.key', $this->dataDir);
28
29
        // generate the TA file if it does not exist
30
        if (!@file_exists($taFile)) {
31
            $this->execOpenVpn(['--genkey', '--secret', $taFile]);
32
        }
33
    }
34
35
    public function get()
36
    {
37
        $taFile = sprintf('%s/ta.key', $this->dataDir);
38
39
        return FileIO::readFile($taFile);
40
    }
41
42 View Code Duplication
    private function execOpenVpn(array $argv)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
43
    {
44
        $command = sprintf(
45
            '/usr/sbin/openvpn %s >/dev/null 2>/dev/null',
46
            implode(' ', $argv)
47
        );
48
49
        exec(
50
            $command,
51
            $commandOutput,
52
            $returnValue
53
        );
54
55
        if (0 !== $returnValue) {
56
            throw new RuntimeException(
57
                sprintf('command "%s" did not complete successfully: "%s"', $command, $commandOutput)
58
            );
59
        }
60
    }
61
}
62