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.

FileCacheStream   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 65
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A open() 0 14 1
A getRandomFilename() 0 4 1
A isOpen() 0 4 1
A isOpening() 0 4 1
A write() 0 4 1
A resume() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of ReactGuzzleRing.
5
 *
6
 ** (c) 2015 Cees-Jan Kiewiet
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace WyriHaximus\React\Guzzle\HttpClient;
12
13
use GuzzleHttp\Stream\StreamInterface;
14
use GuzzleHttp\Stream\Utils as GuzzleUtils;
15
use React\Filesystem\Filesystem;
16
17
/**
18
 * Class FileCacheStream
19
 *
20
 * @package WyriHaximus\React\RingPHP\HttpClient
21
 */
22
class FileCacheStream
23
{
24
    /**
25
     * @var Filesystem
26
     */
27
    protected $filesystem;
28
29
    /**
30
     * @var \React\Filesystem\Node\File
31
     */
32
    protected $file;
33
34
    /**
35
     * @var \React\Filesystem\Stream
36
     */
37
    protected $stream;
38
39
    protected $open = false;
40
    protected $opening = false;
41
42
    public function __construct(array $options)
43
    {
44
        $this->filesystem = Filesystem::create($options['loop']);
45
    }
46
47
    public function open()
48
    {
49
        $this->opening = true;
50
        $file = $this->filesystem->file($this->getRandomFilename());
51
        return $file->exists()->then(function () {
52
            return $this->open();
53
        }, function () use ($file) {
54
            return $file->create()->open('cw')->then(function ($stream) {
55
                $this->open = true;
56
                $this->opening = false;
57
                $this->stream = $stream;
58
            });
59
        });
60
    }
61
62
    protected function getRandomFilename()
63
    {
64
        return sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('wyrihaximus-react-guzzle-ring-', true);
65
    }
66
67
    public function isOpen()
68
    {
69
        return $this->open;
70
    }
71
72
    public function isOpening()
73
    {
74
        return $this->opening;
75
    }
76
77
    public function write($data)
78
    {
79
        $this->stream->write($data);
80
    }
81
82
    public function resume()
83
    {
84
        $this->stream->resume();
85
    }
86
}
87