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

Sequence::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 18

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 18
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\{
7
    Transport\Frame\Value,
8
    Exception\StringNotOfExpectedLength
9
};
10
use Innmind\Math\Algebra\Integer;
11
use Innmind\Immutable\{
12
    Sequence as Seq,
13
    StreamInterface,
14
    Stream,
15
    Str
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 5
    public function __construct(Value ...$values)
27
    {
28 5
        $sequence = new Seq(...$values);
29
        $data = $sequence
30 5
            ->reduce(
31 5
                new Seq,
32 5
                static function(Seq $carry, Value $value): Seq {
33
                    return $carry
34 4
                        ->add(Symbols::symbol(get_class($value)))
35 4
                        ->add($value);
36 5
                }
37
            )
38 5
            ->join('')
39 5
            ->toEncoding('ASCII');
40 5
        $this->value = (string) new UnsignedLongInteger(
41 5
            new Integer($data->length())
42
        );
43 5
        $this->value .= $data;
44 5
        $this->original = $sequence->reduce(
45 5
            new Stream(Value::class),
46 5
            static function(Stream $stream, Value $value): Stream {
47 4
                return $stream->add($value);
1 ignored issue
show
Documentation introduced by
$value is of type object<Innmind\AMQP\Transport\Frame\Value>, but the function expects a object<Innmind\Immutable\T>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
48 5
            }
49
        );
50 5
    }
51
52 2
    public static function fromString(Str $string): Value
53
    {
54 2
        $string = $string->toEncoding('ASCII');
55 2
        $length = UnsignedLongInteger::fromString($string->substring(0, 4))->original();
56 2
        $string = $string->substring(4);
57
58 2
        if ($string->length() !== $length->value()) {
59
            throw new StringNotOfExpectedLength($string, $length->value());
60
        }
61
62 2
        $values = [];
63
64 2
        while ($string->length() !== 0) {
65 2
            $class = Symbols::class((string) $string->substring(0, 1));
66 2
            $element = [$class, 'cut']($string->substring(1))->toEncoding('ASCII');
67 2
            $values[] = [$class, 'fromString']($element);
68 2
            $string = $string->substring($element->length() + 1);
69
        }
70
71 2
        return new self(...$values);
72
    }
73
74 2
    public static function cut(Str $string): Str
75
    {
76 2
        $string = $string->toEncoding('ASCII');
77 2
        $length = UnsignedLongInteger::fromString(
78 2
            UnsignedLongInteger::cut($string)
79 2
        )->original();
80
81 2
        return $string->substring(0, $length->value() + 4);
82
    }
83
84
    /**
85
     * @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...
86
     */
87 4
    public function original(): StreamInterface
88
    {
89 4
        return $this->original;
90
    }
91
92 4
    public function __toString(): string
93
    {
94 4
        return $this->value;
95
    }
96
}
97