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 ( cf4f13...66ac73 )
by François
02:09
created

FileIO::writeFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
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\Common;
19
20
use RuntimeException;
21
22
class FileIO
23
{
24
    public static function readFile($filePath)
25
    {
26
        if (false === $fileData = @file_get_contents($filePath)) {
27
            throw new RuntimeException(sprintf('unable to read file "%s"', $filePath));
28
        }
29
30
        return $filePath;
31
    }
32
33
    public static function readJsonFile($filePath)
34
    {
35
        $fileData = self::readFile($filePath);
36
        $jsonData = json_decode($fileData, true);
0 ignored issues
show
Unused Code introduced by
$jsonData 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...
37
        if (JSON_ERROR_NONE !== json_last_error()) {
38
            throw new RuntimeException(sprintf('unable to decode JSON from file "%s"', $filePath));
39
        }
40
    }
41
42
    public static function writeFile($filePath, $fileData)
43
    {
44
        if (false === @file_put_contents($filePath, $fileData)) {
45
            throw new RuntimeException(sprintf('unable to write file "%s"', $filePath));
46
        }
47
    }
48
49
    public static function writeJsonFile($filePath, $fileJsonData)
50
    {
51
        $fileData = json_encode($fileJsonData);
0 ignored issues
show
Unused Code introduced by
$fileData 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...
52
        if (JSON_ERROR_NONE !== json_last_error()) {
53
            throw new RuntimeException(sprintf('unable to encode JSON for file "%s"', $filePath));
54
        }
55
56
        self::writeFile($filePath, json_encode($fileJsonData));
57
    }
58
}
59