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.
Passed
Pull Request — develop (#1)
by Baptiste
01:41
created

Bits::fromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 1
dl 0
loc 23
ccs 19
cts 19
cp 1
crap 1
rs 9.7333
c 0
b 0
f 0
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
        array_unshift($bits, $first);
23 92
        $value = 0;
24 92
        $stream = new Stream('bool');
25
26 92
        foreach ($bits as $i => $bit) {
27 92
            $stream = $stream->add($bit);
28 92
            $bit = (int) $bit;
29 92
            $value |= $bit << $i;
30
        }
31
32 92
        $this->value = chr($value);
33 92
        $this->original = $stream;
34 92
    }
35
36 58
    public static function fromStream(Readable $stream): Value
37
    {
38 58
        return new self(
39
            ...$stream
40 58
                ->read(1)
41 58
                ->toEncoding('ASCII')
42 58
                ->chunk()
43 58
                ->reduce(
44 58
                    new Seq,
45 58
                    static function(Seq $bits, Str $bit): Seq {
46 58
                        return (new Str(decbin(ord((string) $bit))))
47 58
                            ->chunk()
48 58
                            ->reduce(
49 58
                                $bits,
50 58
                                static function(Seq $bits, Str $bit): Seq {
51 58
                                    return $bits->add((int) (string) $bit);
52 58
                                }
53
                            );
54 58
                    }
55
                )
56 58
                ->map(static function(int $bit): bool {
57 58
                    return (bool) $bit;
58 58
                })
59 58
                ->reverse()
60
        );
61
    }
62
63
    /**
64
     * @return StreamInterface<bool>
65
     */
66 44
    public function original(): StreamInterface
67
    {
68 44
        return $this->original;
69
    }
70
71 91
    public function __toString(): string
72
    {
73 91
        return $this->value;
74
    }
75
}
76