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.

TestingTokenStorage   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 4 1
A setToken() 0 3 1
A hasToken() 0 3 1
A __construct() 0 8 4
A getToken() 0 6 2
A removeToken() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LM\AuthAbstractor\Implementation;
6
7
use Symfony\Component\Security\Csrf\Exception\TokenNotFoundException;
8
use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
9
use UnexpectedValueException;
10
11
/**
12
 * This is an implementation of TokenStorageInterface that is used in unit
13
 * tests.
14
 *
15
 * @internal
16
 * @todo Add one using sessions?
17
 */
18
class TestingTokenStorage implements TokenStorageInterface
19
{
20
    /** @var string */
21
    private $dataDir;
22
23
    /**
24
     * @param string $projectRootPath The root directory to the project.
25
     */
26
    public function __construct(string $projectRootPath)
27
    {
28
        if (!file_exists($projectRootPath.'/tmp') && !mkdir($projectRootPath.'/tmp', 0744)) {
29
            throw new UnexpectedValueException();
30
        }
31
        $this->dataDir = $projectRootPath.'/tmp/'.rand();
32
        if (!mkdir($this->dataDir)) {
33
            throw new UnexpectedValueException();
34
        }
35
    }
36
37
    /**
38
     * @todo Should check that the folder has been deleted.
39
     */
40
    public function __destruct()
41
    {
42
        array_map('unlink', glob($this->dataDir.'/*'));
43
        rmdir($this->dataDir);
44
    }
45
46
    public function getToken($tokenId)
47
    {
48
        if (file_exists($this->dataDir.'/'.$tokenId)) {
49
            return file_get_contents($this->dataDir.'/'.$tokenId);
50
        } else {
51
            throw new TokenNotFoundException();
52
        }
53
    }
54
55
    /**
56
     * @todo Check for case where file_put_contents returns false.
57
     */
58
    public function setToken($tokenId, $token)
59
    {
60
        file_put_contents($this->dataDir.'/'.$tokenId, $token);
61
    }
62
63
    public function removeToken($tokenId)
64
    {
65
        if (file_exists($this->dataDir.'/'.$tokenId)) {
66
            return unlink($this->dataDir.'/'.$tokenId);
0 ignored issues
show
Bug Best Practice introduced by
The expression return unlink($this->dataDir . '/' . $tokenId) returns the type boolean which is incompatible with the return type mandated by Symfony\Component\Securi...nterface::removeToken() of null|string.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
67
        } else {
68
            return;
69
        }
70
    }
71
72
    public function hasToken($tokenId)
73
    {
74
        return file_exists($this->dataDir.'/'.$tokenId);
75
    }
76
}
77