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 — develop ( 081f57...404db9 )
by Baptiste
12s queued 11s
created

Bits   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 59
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 14 3
A original() 0 3 1
A __construct() 0 3 1
A fromStream() 0 24 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQP\Transport\Frame\Value;
5
6
use Innmind\AMQP\Transport\Frame\Value;
7
use Innmind\Stream\Readable;
8
use Innmind\Immutable\{
9
    StreamInterface,
10
    Stream,
11
    Str,
12
    Sequence as Seq
13
};
14
15
final class Bits implements Value
16
{
17
    private $value;
18
    private $original;
19
20 92
    public function __construct(bool $first, bool ...$bits)
21
    {
22 92
        $this->original = Stream::of('bool', $first, ...$bits);
23 92
    }
24
25 58
    public static function fromStream(Readable $stream): Value
26
    {
27 58
        return new self(
28
            ...$stream
29 58
                ->read(1)
30 58
                ->toEncoding('ASCII')
31 58
                ->chunk()
32 58
                ->reduce(
33 58
                    new Seq,
34 58
                    static function(Seq $bits, Str $bit): Seq {
35 58
                        return (new Str(decbin(ord((string) $bit))))
36 58
                            ->chunk()
37 58
                            ->reduce(
38 58
                                $bits,
39 58
                                static function(Seq $bits, Str $bit): Seq {
40 58
                                    return $bits->add((int) (string) $bit);
41 58
                                }
42
                            );
43 58
                    }
44
                )
45 58
                ->map(static function(int $bit): bool {
46 58
                    return (bool) $bit;
47 58
                })
48 58
                ->reverse()
49
        );
50
    }
51
52
    /**
53
     * @return StreamInterface<bool>
54
     */
55 44
    public function original(): StreamInterface
56
    {
57 44
        return $this->original;
58
    }
59
60 91
    public function __toString(): string
61
    {
62 91
        if (\is_null($this->value)) {
63 91
            $value = 0;
64
65 91
            foreach ($this->original as $i => $bit) {
66 91
                $bit = (int) $bit;
67 91
                $value |= $bit << $i;
68
            }
69
70 91
            $this->value = chr($value);
71
        }
72
73 91
        return $this->value;
74
    }
75
}
76