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 ( faae32...638f88 )
by Baptiste
03:29
created

Bits::fromString()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 19
cts 19
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 1
crap 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\Immutable\{
8
    StreamInterface,
9
    Stream,
10
    Str,
11
    Sequence as Seq
12
};
13
14
final class Bits implements Value
15
{
16
    private $value;
17
    private $original;
18
19 12
    public function __construct(bool $first, bool ...$bits)
20
    {
21 12
        array_unshift($bits, $first);
22 12
        $value = 0;
23 12
        $stream = new Stream('bool');
24
25 12
        foreach ($bits as $i => $bit) {
26 12
            $stream = $stream->add($bit);
27 12
            $bit = (int) $bit;
28 12
            $value |= $bit << $i;
29
        }
30
31 12
        $this->value = chr($value);
32 12
        $this->original = $stream;
33 12
    }
34
35 5
    public static function fromString(Str $string): Value
36
    {
37 5
        return new self(
38
            ...$string
39 5
                ->toEncoding('ASCII')
40 5
                ->chunk()
41 5
                ->reduce(
42 5
                    new Seq,
43 5
                    static function(Seq $bits, Str $bit): Seq {
44 5
                        return (new Str(decbin(ord((string) $bit))))
45 5
                            ->chunk()
46 5
                            ->reduce(
47 5
                                $bits,
48 5
                                static function(Seq $bits, Str $bit): Seq {
49 5
                                    return $bits->add((int) (string) $bit);
50 5
                                }
51
                            );
52 5
                    }
53
                )
54 5
                ->map(static function(int $bit): bool {
55 5
                    return (bool) $bit;
56 5
                })
57 5
                ->reverse()
58
        );
59
    }
60
61 5
    public static function cut(Str $string): Str
62
    {
63 5
        return $string->toEncoding('ASCII')->substring(0, 1);
64
    }
65
66
    /**
67
     * @return StreamInterface<bool>
0 ignored issues
show
Documentation introduced by
The doc-type StreamInterface<bool> could not be parsed: Expected "|" or "end of type", but got "<" at position 15. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
68
     */
69 11
    public function original(): StreamInterface
70
    {
71 11
        return $this->original;
72
    }
73
74 11
    public function __toString(): string
75
    {
76 11
        return $this->value;
77
    }
78
}
79