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 ( 00c2b4...ff24ee )
by François
02:33
created

VootToken   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 69.09 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 2
dl 38
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A getVootToken() 10 10 2
A setVootToken() 20 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Copyright 2016 François Kooman <[email protected]>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
namespace fkooman\VPN\Server;
19
20
use fkooman\IO\IOInterface;
21
use fkooman\IO\IO;
22
23
class VootToken
24
{
25
    /** @var string */
26
    private $configDir;
27
28
    /** @var \fkooman\IO\IOInterface */
29
    private $io;
30
31 View Code Duplication
    public function __construct($configDir, IOInterface $io = null)
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...
32
    {
33
        $this->configDir = $configDir;
34
        if (is_null($io)) {
35
            $io = new IO();
36
        }
37
        $this->io = $io;
38
    }
39
40
    /**
41
     * Check whether a particular user has a VOOT token set.
42
     */
43 View Code Duplication
    public function getVootToken($userId)
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...
44
    {
45
        $vootTokenFile = sprintf('%s/%s', $this->configDir, $userId);
46
47
        if ($this->io->isFile($vootTokenFile)) {
48
            return $this->io->readFile($vootTokenFile);
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * Set or delete the VOOT token for a particular user.
56
     */
57 View Code Duplication
    public function setVootToken($userId, $vootToken)
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...
58
    {
59
        $vootTokenFile = sprintf('%s/%s', $this->configDir, $userId);
60
61
        if (false === $vootToken) {
62
            // remove the token
63
            if ($this->io->isFile($vootTokenFile)) {
64
                $this->io->deleteFile($vootTokenFile);
65
66
                return true;
67
            }
68
69
            return false;
70
        }
71
72
        // set the token, if it is already set override
73
        $this->io->writeFile($vootTokenFile, $vootToken, true);
0 ignored issues
show
Security File Manipulation introduced by
$vootToken can contain request data and is used in file manipulation context(s) leading to a potential security vulnerability.

General Strategies to prevent injection

In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:

if ( ! in_array($value, array('this-is-allowed', 'and-this-too'), true)) {
    throw new \InvalidArgumentException('This input is not allowed.');
}

For numeric data, we recommend to explicitly cast the data:

$sanitized = (integer) $tainted;
Loading history...
74
75
        return true;
76
    }
77
}
78