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 ( 0c5d13...810fab )
by Cees-Jan
19:37 queued 09:36
created

WritableStreamBase64Decode::close()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\Stream\Base64;
4
5
use Evenement\EventEmitterTrait;
6
use React\Stream\WritableStreamInterface;
7
8 View Code Duplication
final class WritableStreamBase64Decode implements WritableStreamInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
9
{
10
    use EventEmitterTrait;
11
12
    /**
13
     * @var WritableStreamInterface
14
     */
15
    private $stream;
16
17
    /**
18
     * @var string
19
     */
20
    private $buffer = '';
21
22
    /**
23
     * WritableStreamHash constructor.
24
     * @param WritableStreamInterface $stream
25
     */
26
    public function __construct(WritableStreamInterface $stream)
27
    {
28
        $this->stream = $stream;
29
    }
30
31
    public function isWritable()
32
    {
33
        return $this->stream->isWritable();
34
    }
35
36
    public function write($data)
37
    {
38
        $this->buffer .= $data;
39
40
        return $this->stream->write($this->processBuffer());
41
    }
42
43
    public function end($data = null)
44
    {
45
        $this->buffer .= $data;
46
        $this->stream->end(
47
            $this->processBuffer() . base64_decode($this->buffer)
48
        );
49
        $this->buffer = '';
50
    }
51
52
    public function close()
53
    {
54
        $this->stream->close();
55
    }
56
57
    private function processBuffer(): string
58
    {
59
        $length = strlen($this->buffer);
60
        $buffer = base64_decode(substr($this->buffer, 0, $length - $length % 4));
61
        $this->buffer = substr($this->buffer, $length - $length % 4);
62
63
        return $buffer;
64
    }
65
}
66