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.

FileCache   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 78.38%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 1
dl 0
loc 80
rs 10
c 0
b 0
f 0
ccs 29
cts 37
cp 0.7838

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A fetch() 0 18 5
A contains() 0 4 1
A save() 0 15 3
A delete() 0 10 2
A getStats() 0 4 1
A filename() 0 8 2
1
<?php
2
3
namespace JDesrosiers\Resourceful\FileCache;
4
5
use Doctrine\Common\Cache\Cache;
6
use Symfony\Component\Filesystem\Exception\IOException;
7
use Symfony\Component\Filesystem\Filesystem;
8
9
class FileCache implements Cache
10
{
11
    private $filesystem;
12
    private $location;
13
14 16
    public function __construct($location)
15
    {
16 16
        $this->filesystem = new Filesystem();
17 16
        $this->location = $location;
18
19 16
        if (!$this->filesystem->exists($this->location)) {
20 6
            $this->filesystem->mkdir($this->location);
21
        }
22 16
    }
23
24 14
    public function fetch($id)
25
    {
26 14
        if (!$this->contains($id)) {
27 2
            return false;
28
        }
29
30 12
        $json = file_get_contents($this->filename($id));
31 12
        if ($json === false) {
32
            return false;
33
        }
34
35 12
        $data = json_decode($json);
36 12
        if ($data === null && json_last_error() !== JSON_ERROR_NONE) {
37
            return false;
38
        }
39
40 12
        return $data;
41
    }
42
43 14
    public function contains($id)
44
    {
45 14
        return $this->filesystem->exists($this->filename($id));
46
    }
47
48 3
    public function save($id, $data, $lifeTime = null)
49
    {
50 3
        $json = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
51 3
        if ($json === false) {
52
            return false;
53
        }
54
55
        try {
56 3
            $this->filesystem->dumpFile($this->filename($id), $json);
57
        } catch (IOException $ioe) {
58
            return false;
59
        }
60
61 3
        return true;
62
    }
63
64 2
    public function delete($id)
65
    {
66
        try {
67 2
            $this->filesystem->remove($this->filename($id));
68
        } catch (IOException $ioe) {
69
            return false;
70
        }
71
72 2
        return true;
73
    }
74
75 1
    public function getStats()
76
    {
77 1
        return null;
78
    }
79
80 15
    protected function filename($id)
81
    {
82 15
        if (is_dir("$this->location/$id")) {
83
            $id .= "/index";
84
        }
85
86 15
        return "$this->location/$id.json";
87
    }
88
}
89