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.

WritableStreamHash::isWritable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
     * @param string                  $algo
24
     * @param string|null             $key
25
     */
26 12232
    public function __construct(WritableStreamInterface $stream, string $algo, string $key = null)
27
    {
28 12232
        $this->stream = $stream;
29 12232
        $options = [$algo];
30 12232 View Code Duplication
        if ($key !== null && \strlen($key) > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31 6116
            $options[] = \HASH_HMAC;
32 6116
            $options[] = $key;
33
        }
34 12232
        $this->context = \hash_init(...$options);
35 View Code Duplication
        $this->stream->once('close', function () use ($algo): void {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36 12232
            $hash = \hash_final($this->context, true);
37 12232
            if (\count($this->listeners('hash')) > 0) {
38 12232
                $this->emit('hash', [
39 12232
                    \bin2hex($hash),
40 12232
                    $algo,
41
                ]);
42
            }
43 12232
            if (\count($this->listeners('hash_raw')) > 0) {
44 12232
                $this->emit('hash_raw', [
45 12232
                    $hash,
46 12232
                    $algo,
47
                ]);
48
            }
49 12232
            $this->emit('close');
50 12232
        });
51 12232
    }
52
53
    public function isWritable()
54
    {
55
        return $this->stream->isWritable();
56
    }
57
58 12232
    public function write($data)
59
    {
60 12232
        \hash_update($this->context, $data);
61
62 12232
        return $this->stream->write($data);
63
    }
64
65 12232
    public function end($data = null): void
66
    {
67 12232
        if ($data !== null) {
68
            \hash_update($this->context, $data);
69
        }
70 12232
        $this->stream->end($data);
71 12232
    }
72
73
    public function close(): void
74
    {
75
        $this->stream->close();
76
    }
77
}
78