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 ( 71cc31...7de261 )
by François
04:22
created

CommonNames::setDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
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\Api;
19
20
use SURFnet\VPN\Common\FileIO;
21
use RuntimeException;
22
23
/**
24
 * Manages common name configuration.
25
 *
26
 * XXX deal better with exceptions, not everything is a RuntimeException,
27
 */
28
class CommonNames
29
{
30
    /** @var string */
31
    private $disableDir;
32
33
    public function __construct($dataDir)
34
    {
35
        $this->disableDir = sprintf('%s/disabled', $dataDir);
36
        FileIO::createDir($this->disableDir, 0711);
37
    }
38
39 View Code Duplication
    public function getDisabled()
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...
40
    {
41
        $disabledList = [];
42
        if (false === $fileList = glob(sprintf('%s/*', $this->disableDir), GLOB_ERR)) {
43
            throw new RuntimeException(sprintf('unable to read directory "%s"', $this->disableDir));
44
        }
45
46
        foreach ($fileList as $fileName) {
47
            $disabledList[] = basename($fileName);
48
        }
49
50
        return $disabledList;
51
    }
52
53
    public function isDisabled($commonName)
54
    {
55
        $disableFile = sprintf('%s/%s', $this->disableDir, $commonName);
0 ignored issues
show
Unused Code introduced by
$disableFile is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
56
57
        return @file_exists($commonName);
58
    }
59
60
    public function setDisabled($commonName)
61
    {
62
        $disableFile = sprintf('%s/%s', $this->disableDir, $commonName);
63
        FileIO::writeFile($disableFile, time(), 0644);
64
    }
65
66
    public function setEnabled($commonName)
67
    {
68
        $disableFile = sprintf('%s/%s', $this->disableDir, $commonName);
69
        FileIO::deleteFile($disableFile);
70
    }
71
}
72