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.

ShortString::of()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
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\Transport\Frame\Value;
7
use Innmind\Math\Algebra\Integer;
8
use Innmind\Stream\Readable;
9
use Innmind\Immutable\Str;
10
11
final class ShortString implements Value
12
{
13
    private $value;
14
    private $original;
15
16 194
    public function __construct(Str $string)
17
    {
18 194
        $this->original = $string;
19 194
    }
20
21 136
    public static function of(Str $string): self
22
    {
23 136
        UnsignedOctet::of(new Integer($string->toEncoding('ASCII')->length()));
24
25 134
        return new self($string);
26
    }
27
28 138
    public static function fromStream(Readable $stream): Value
29
    {
30 138
        $length = UnsignedOctet::fromStream($stream)->original();
31
32 138
        return new self($stream->read($length->value()));
33
    }
34
35 144
    public function original(): Str
36
    {
37 144
        return $this->original;
38
    }
39
40 192
    public function __toString(): string
41
    {
42 192
        return $this->value ?? $this->value = new UnsignedOctet(
43 192
            new Integer($this->original->toEncoding('ASCII')->length())
44 192
        ).$this->original;
45
    }
46
}
47