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::__construct()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2222
c 0
b 0
f 0
cc 6
nc 6
nop 1
1
<?php
2
3
namespace Minime\Annotations\Cache;
4
5
use Minime\Annotations\Interfaces\CacheInterface;
6
7
/**
8
 * A file storage cache implementation
9
 *
10
 * @package Minime\Annotations
11
 */
12
class FileCache implements CacheInterface
13
{
14
    /**
15
     * Cache storage path
16
     *
17
     * @var string
18
     */
19
    protected $path;
20
21
    /**
22
     * Cache entry file extension
23
     *
24
     * @var string
25
     */
26
    protected $extension = 'annotations';
27
28
    /**
29
     *
30
     * @param string $path custom sorage path
31
     */
32
    public function __construct($path = null)
33
    {
34
        $this->path = $path;
35
36
        if (! $this->path) {
37
            $this->path = sys_get_temp_dir() . '/minime-annotations/';
38
            if (! is_dir($this->path) ) {
39
                mkdir($this->path);
40
            }
41
        }
42
43
        if (! is_dir($this->path) || ! is_writable($this->path) || ! is_readable($this->path)) {
44
            throw new \InvalidArgumentException("Cache path is not a writable/readable directory: {$this->path}.");
45
        }
46
    }
47
48
    public function getKey($docblock)
49
    {
50
        return md5($docblock);
51
    }
52
53
    public function set($key, array $annotations)
54
    {
55
        $file = $this->getFileName($key);
56
        if (! file_exists($file)) {
57
            file_put_contents($file, serialize($annotations));
58
        }
59
    }
60
61
    public function get($key)
62
    {
63
        $file = $this->getFileName($key);
64
        if (file_exists($file)) {
65
            return unserialize(file_get_contents($file));
66
        }
67
68
        return [];
69
    }
70
71
    public function clear()
72
    {
73
        foreach (glob($this->path . "*{.{$this->extension}}", GLOB_BRACE | GLOB_NOSORT) as $file) {
74
            unlink($file);
75
        }
76
    }
77
78
    protected function getFileName($key)
79
    {
80
        return $this->path . $key . '.' . $this->extension;
81
    }
82
83
}
84