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 ( 721ff2...8a7a60 )
by Cees-Jan
22:04
created

Filesystem::set()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
cc 2
eloc 10
nc 2
nop 2
crap 2
1
<?php
2
3
namespace WyriHaximus\React\Cache;
4
5
use React\Cache\CacheInterface;
6
use React\Filesystem\Filesystem as ReactFilesystem;
7
use React\Filesystem\Node\FileInterface;
8
use React\Promise\PromiseInterface;
9
10
class Filesystem implements CacheInterface
11
{
12
    /**
13
     * @var ReactFilesystem
14
     */
15
    protected $filesystem;
16
17
    /**
18
     * @var string
19
     */
20
    protected $path;
21
22
    /**
23
     * filesystem constructor.
24
     * @param ReactFilesystem $filesystem
25
     * @param string $path
26
     */
27 6
    public function __construct(ReactFilesystem $filesystem, $path)
28
    {
29 6
        $this->filesystem = $filesystem;
30 6
        $this->path = $path;
31 6
    }
32
33
    /**
34
     * @param string $key
35
     * @return PromiseInterface
36
     */
37 2
    public function get($key)
38
    {
39 2
        $file = $this->getFile($key);
40
        return $file->exists()->then(function () use ($file) {
41 1
            return $file->getContents();
42 2
        });
43
    }
44
45
    /**
46
     * @param string $key
47
     * @param mixed $value
48
     */
49 2
    public function set($key, $value)
50
    {
51 2
        $file = $this->getFile($key);
52 2
        if (strpos($key, DIRECTORY_SEPARATOR) === false) {
53 1
            $file->putContents($value);
54 1
            return;
55
        }
56
57 1
        $path = explode(DIRECTORY_SEPARATOR, $key);
58 1
        array_pop($path);
59 1
        $path = implode(DIRECTORY_SEPARATOR, $path);
60
61
        $this->filesystem->dir($this->path . $path)->createRecursive()->then(function () use ($file, $value) {
62 1
            $file->putContents($value);
63 1
        });
64 1
    }
65
66
    /**
67
     * @param string $key
68
     */
69 2
    public function remove($key)
70
    {
71 2
        $file = $this->getFile($key);
72 2
        $file->exists()->then(function () use ($file) {
73 1
            $file->remove();
74 2
        });
75 2
    }
76
77
    /**
78
     * @param $key
79
     * @return FileInterface
80
     */
81 6
    protected function getFile($key)
82
    {
83 6
        return $this->filesystem->file($this->path . $key);
84
    }
85
}
86