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
Push — master ( 778995...e0837d )
by Baptiste
03:36
created

Table::fromStream()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 18
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
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\{
7
    Transport\Frame\Value,
8
    Exception\UnboundedTextCannotBeWrapped,
9
};
10
use Innmind\Math\Algebra\Integer;
11
use Innmind\Stream\Readable;
12
use Innmind\Immutable\{
13
    Str,
14
    Sequence as Seq,
15
    MapInterface,
16
    Map,
17
};
18
use function Innmind\Immutable\assertMap;
19
20
final class Table implements Value
21
{
22
    private $value;
23
    private $original;
24
25
    /**
26
     * @param MapInterface<string, Value> $map
27
     */
28 132
    public function __construct(MapInterface $map)
29
    {
30 132
        assertMap('string', Value::class, $map, 1);
31
32
        $texts = $map->filter(static function(string $key, Value $value): bool {
33 120
            return $value instanceof Text;
34 130
        });
35
36 130
        if ($texts->size() > 0) {
37 2
            throw new UnboundedTextCannotBeWrapped;
38
        }
39
40 128
        $this->original = $map;
41 128
    }
42
43 104
    public static function fromStream(Readable $stream): Value
44
    {
45 104
        $length = UnsignedLongInteger::fromStream($stream)->original();
46 104
        $position = $stream->position()->toInt();
47 104
        $boundary = $position + $length->value();
48
49 104
        $map = new Map('string', Value::class);
50
51 104
        while ($position < $boundary) {
52 98
            $key = ShortString::fromStream($stream)->original();
53 98
            $class = Symbols::class((string) $stream->read(1));
54
55 98
            $map = $map->put((string) $key, [$class, 'fromStream']($stream));
56
57 98
            $position = $stream->position()->toInt();
58
        }
59
60 104
        return new self($map);
61
    }
62
63
    /**
64
     * @return MapInterface<string, Value>
65
     */
66 26
    public function original(): MapInterface
67
    {
68 26
        return $this->original;
69
    }
70
71 126
    public function __toString(): string
72
    {
73 126
        if (\is_null($this->value)) {
74
            $data = $this
75 126
                ->original
76 126
                ->reduce(
77 126
                    new Seq,
78
                    static function(Seq $sequence, string $key, Value $value): Seq {
79
                        return $sequence
80 118
                            ->add(new ShortString(new Str($key)))
81 118
                            ->add(Symbols::symbol(\get_class($value)))
82 118
                            ->add($value);
83 126
                    }
84
                )
85 126
                ->join('')
86 126
                ->toEncoding('ASCII');
87
88 126
            $this->value = (string) UnsignedLongInteger::of(
89 126
                new Integer($data->length())
90
            );
91 126
            $this->value .= $data;
92
        }
93
94 126
        return $this->value;
95
    }
96
}
97