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

Sequence   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Test Coverage

Coverage 97.87%

Importance

Changes 0
Metric Value
dl 0
loc 85
c 0
b 0
f 0
wmc 8
lcom 0
cbo 9
ccs 46
cts 47
cp 0.9787
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 34 2
A fromString() 0 21 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
    Sequence as Seq,
14
    StreamInterface,
15
    Stream,
16
    Str
17
};
18
19
/**
20
 * It's an array, but "array" is a reserved keyword in PHP
21
 */
22
final class Sequence implements Value
23
{
24
    private $value;
25
    private $original;
26
27 7
    public function __construct(Value ...$values)
28
    {
29 7
        $sequence = new Seq(...$values);
30
31 7
        $texts = $sequence->filter(static function(Value $value): bool {
32 6
            return $value instanceof Text;
33 7
        });
34
35 7
        if ($texts->size() > 0) {
36 1
            throw new UnboundedTextCannotBeWrapped;
37
        }
38
39
        $data = $sequence
40 6
            ->reduce(
41 6
                new Seq,
42 6
                static function(Seq $carry, Value $value): Seq {
43
                    return $carry
44 5
                        ->add(Symbols::symbol(get_class($value)))
45 5
                        ->add($value);
46 6
                }
47
            )
48 6
            ->join('')
49 6
            ->toEncoding('ASCII');
50 6
        $this->value = (string) new UnsignedLongInteger(
51 6
            new Integer($data->length())
52
        );
53 6
        $this->value .= $data;
54 6
        $this->original = $sequence->reduce(
55 6
            new Stream(Value::class),
56 6
            static function(Stream $stream, Value $value): Stream {
57 5
                return $stream->add($value);
58 6
            }
59
        );
60 6
    }
61
62 3
    public static function fromString(Str $string): Value
63
    {
64 3
        $string = $string->toEncoding('ASCII');
65 3
        $length = UnsignedLongInteger::fromString($string->substring(0, 4))->original();
66 3
        $string = $string->substring(4);
67
68 3
        if ($string->length() !== $length->value()) {
69
            throw new StringNotOfExpectedLength($string, $length->value());
70
        }
71
72 3
        $values = [];
73
74 3
        while ($string->length() !== 0) {
75 3
            $class = Symbols::class((string) $string->substring(0, 1));
76 3
            $element = [$class, 'cut']($string->substring(1))->toEncoding('ASCII');
77 3
            $values[] = [$class, 'fromString']($element);
78 3
            $string = $string->substring($element->length() + 1);
79
        }
80
81 3
        return new self(...$values);
82
    }
83
84 3
    public static function cut(Str $string): Str
85
    {
86 3
        $string = $string->toEncoding('ASCII');
87 3
        $length = UnsignedLongInteger::fromString(
88 3
            UnsignedLongInteger::cut($string)
89 3
        )->original();
90
91 3
        return $string->substring(0, $length->value() + 4);
92
    }
93
94
    /**
95
     * @return StreamInterface<Value>
0 ignored issues
show
Documentation introduced by
The doc-type StreamInterface<Value> 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...
96
     */
97 5
    public function original(): StreamInterface
98
    {
99 5
        return $this->original;
100
    }
101
102 5
    public function __toString(): string
103
    {
104 5
        return $this->value;
105
    }
106
}
107