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 ( a0d7f6...1c3e27 )
by Baptiste
02:53
created

Table   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 99
c 0
b 0
f 0
wmc 10
lcom 0
cbo 11
ccs 51
cts 51
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 39 4
B fromString() 0 27 3
A cut() 0 9 1
A original() 0 4 1
A __toString() 0 4 1
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\StringNotOfExpectedLength,
9
    Exception\UnboundedTextCannotBeWrapped
10
};
11
use Innmind\Math\Algebra\Integer;
12
use Innmind\Immutable\{
13
    Str,
14
    Sequence as Seq,
15
    MapInterface,
16
    Map
17
};
18
19
final class Table implements Value
20
{
21
    private $value;
22
    private $original;
23
24
    /**
25
     * @param MapInterface<string, Value> $map
26
     */
27 66
    public function __construct(MapInterface $map)
28
    {
29
        if (
30 66
            (string) $map->keyType() !== 'string' ||
31 66
            (string) $map->valueType() !== Value::class
32
        ) {
33 1
            throw new \TypeError(sprintf(
34 1
                'Argument 1 must be of type MapInterface<string, %s>',
35 1
                Value::class
36
            ));
37
        }
38
39 65
        $texts = $map->filter(static function(string $key, Value $value): bool {
40 59
            return $value instanceof Text;
41 65
        });
42
43 65
        if ($texts->size() > 0) {
44 1
            throw new UnboundedTextCannotBeWrapped;
45
        }
46
47
        $data = $map
48 64
            ->reduce(
49 64
                new Seq,
50 64
                static function(Seq $sequence, string $key, Value $value): Seq {
51
                    return $sequence
52 58
                        ->add(new ShortString(new Str($key)))
53 58
                        ->add(Symbols::symbol(get_class($value)))
54 58
                        ->add($value);
55 64
                }
56
            )
57 64
            ->join('')
58 64
            ->toEncoding('ASCII');
59
60 64
        $this->value = (string) new UnsignedLongInteger(
61 64
            new Integer($data->length())
62
        );
63 64
        $this->value .= $data;
64 64
        $this->original = $map;
65 64
    }
66
67 52
    public static function fromString(Str $string): Value
68
    {
69 52
        $string = $string->toEncoding('ASCII');
70 52
        $length = UnsignedLongInteger::fromString($string->substring(0, 4))->original();
71 52
        $string = $string->substring(4);
72
73 52
        if ($string->length() !== $length->value()) {
74 1
            throw new StringNotOfExpectedLength($string, $length->value());
75
        }
76
77 51
        $map = new Map('string', Value::class);
78
79 51
        while ($string->length() !== 0) {
80 48
            $key = ShortString::cut($string);
81 48
            $string = $string->toEncoding('ASCII')->substring($key->length());
82 48
            $key = ShortString::fromString($key)->original();
83
84 48
            $class = Symbols::class((string) $string->substring(0, 1));
85 48
            $element = [$class, 'cut']($string->substring(1))->toEncoding('ASCII');
86
87 48
            $map = $map->put((string) $key, [$class, 'fromString']($element));
88
89 48
            $string = $string->substring($element->length() + 1);
90
        }
91
92 51
        return new self($map);
93
    }
94
95 51
    public static function cut(Str $string): Str
96
    {
97 51
        $string = $string->toEncoding('ASCII');
98 51
        $length = UnsignedLongInteger::fromString(
99 51
            UnsignedLongInteger::cut($string)
100 51
        )->original();
101
102 51
        return $string->substring(0, $length->value() + 4);
103
    }
104
105
    /**
106
     * @return MapInterface<string, Value>
0 ignored issues
show
Documentation introduced by
The doc-type MapInterface<string, could not be parsed: Expected "|" or "end of type", but got "<" at position 12. (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...
107
     */
108 13
    public function original(): MapInterface
109
    {
110 13
        return $this->original;
111
    }
112
113 63
    public function __toString(): string
114
    {
115 63
        return $this->value;
116
    }
117
}
118