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

ShortString   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 95.45%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 46
loc 46
ccs 21
cts 22
cp 0.9545
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A fromString() 12 12 2
A cut() 7 7 1
A original() 4 4 1
A __toString() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Str;
12
13 View Code Duplication
final class ShortString implements Value
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    private $value;
16
    private $original;
17
18 10
    public function __construct(Str $string)
19
    {
20 10
        $this->original = $string;
21 10
        $string = $string->toEncoding('ASCII');
22 10
        $this->value = (string) new UnsignedOctet(
23 10
            new Integer($string->length())
24
        );
25 9
        $this->value .= $string;
26 9
    }
27
28 4
    public static function fromString(Str $string): Value
29
    {
30 4
        $string = $string->toEncoding('ASCII');
31 4
        $length = UnsignedOctet::fromString($string->substring(0, 1))->original();
32 4
        $string = $string->substring(1);
33
34 4
        if ($string->length() !== $length->value()) {
35
            throw new StringNotOfExpectedLength($string, $length->value());
36
        }
37
38 4
        return new self($string);
39
    }
40
41 4
    public static function cut(Str $string): Str
42
    {
43 4
        $string = $string->toEncoding('ASCII');
44 4
        $length = UnsignedOctet::fromString($string->substring(0, 1))->original();
45
46 4
        return $string->substring(0, $length->value() + 1);
47
    }
48
49 6
    public function original(): Str
50
    {
51 6
        return $this->original;
52
    }
53
54 8
    public function __toString(): string
55
    {
56 8
        return $this->value;
57
    }
58
}
59