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

Sequence   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 68
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 31 2
A fromStream() 0 15 2
A __toString() 0 3 1
A original() 0 3 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\UnboundedTextCannotBeWrapped,
9
};
10
use Innmind\Math\Algebra\Integer;
11
use Innmind\Stream\Readable;
12
use Innmind\Immutable\{
13
    Sequence as Seq,
14
    StreamInterface,
15
    Stream,
16
};
17
18
/**
19
 * It's an array, but "array" is a reserved keyword in PHP
20
 */
21
final class Sequence implements Value
22
{
23
    private $value;
24
    private $original;
25
26 7
    public function __construct(Value ...$values)
27
    {
28 7
        $sequence = new Seq(...$values);
29
30 7
        $texts = $sequence->filter(static function(Value $value): bool {
31 6
            return $value instanceof Text;
32 7
        });
33
34 7
        if ($texts->size() > 0) {
35 1
            throw new UnboundedTextCannotBeWrapped;
36
        }
37
38
        $data = $sequence
39 6
            ->reduce(
40 6
                new Seq,
41 6
                static function(Seq $carry, Value $value): Seq {
42
                    return $carry
43 5
                        ->add(Symbols::symbol(get_class($value)))
44 5
                        ->add($value);
45 6
                }
46
            )
47 6
            ->join('')
48 6
            ->toEncoding('ASCII');
49 6
        $this->value = (string) new UnsignedLongInteger(
50 6
            new Integer($data->length())
51
        );
52 6
        $this->value .= $data;
53 6
        $this->original = $sequence->reduce(
54 6
            new Stream(Value::class),
55 6
            static function(Stream $stream, Value $value): Stream {
56 5
                return $stream->add($value);
57 6
            }
58
        );
59 6
    }
60
61 3
    public static function fromStream(Readable $stream): Value
62
    {
63 3
        $length = UnsignedLongInteger::fromStream($stream)->original();
64 3
        $position = $stream->position()->toInt();
65 3
        $boundary = $position + $length->value();
66
67 3
        $values = [];
68
69 3
        while ($position < $boundary) {
70 3
            $class = Symbols::class((string) $stream->read(1));
71 3
            $values[] = [$class, 'fromStream']($stream);
72 3
            $position = $stream->position()->toInt();
73
        }
74
75 3
        return new self(...$values);
76
    }
77
78
    /**
79
     * @return StreamInterface<Value>
80
     */
81 5
    public function original(): StreamInterface
82
    {
83 5
        return $this->original;
84
    }
85
86 5
    public function __toString(): string
87
    {
88 5
        return $this->value;
89
    }
90
}
91