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 ( 80e1a2...dbc788 )
by Cees-Jan
01:26
created

WritableStreamHash   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 72.72%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 53
ccs 16
cts 22
cp 0.7272
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A isWritable() 0 4 1
A write() 0 6 1
A end() 0 7 2
A close() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Stream\Hash;
4
5
use Evenement\EventEmitter;
6
use React\Stream\WritableStreamInterface;
7
8
final class WritableStreamHash extends EventEmitter implements WritableStreamInterface
9
{
10
    /**
11
     * @var WritableStreamInterface
12
     */
13
    private $stream;
14
15
    /**
16
     * @var resource
17
     */
18
    private $context;
19
20
    /**
21
     * WritableStreamHash constructor.
22
     * @param WritableStreamInterface $stream
23
     */
24 184
    public function __construct(WritableStreamInterface $stream, string $algo, int $options = 0, string $key = '')
25
    {
26 184
        $this->stream = $stream;
27 184
        $this->context = hash_init($algo, $options, $key);
28 184
        $this->stream->once('close', function () use ($algo) {
29 184
            $this->emit('hash', [
30 184
                hash_final($this->context),
31 184
                $algo,
32
            ]);
33 184
        });
34 184
    }
35
36
    public function isWritable()
37
    {
38
        return $this->stream->isWritable();
39
    }
40
41 184
    public function write($data)
42
    {
43 184
        hash_update($this->context, $data);
44
45 184
        return $this->stream->write($data);
46
    }
47
48 184
    public function end($data = null)
49
    {
50 184
        if ($data !== null) {
51
            hash_update($this->context, $data);
52
        }
53 184
        $this->stream->end($data);
54 184
    }
55
56
    public function close()
57
    {
58
        $this->stream->close();
59
    }
60
}
61