Passed
Push — master ( 6d1632...ddd5df )
by Thorsten
01:48
created

StreamId   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 47.06%

Importance

Changes 0
Metric Value
dl 42
loc 42
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2
ccs 8
cts 17
cp 0.4706
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNative() 4 4 1
A makeEmpty() 4 4 1
A equals() 5 5 1
A isEmpty() 4 4 1
A __construct() 5 5 1
A toNative() 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
/**
3
 * This file is part of the daikon-cqrs/cqrs project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace Daikon\EventSourcing\EventStore;
12
13
use Assert\Assertion;
14
use Daikon\Entity\ValueObject\ValueObjectInterface;
15
16 View Code Duplication
final class StreamId implements ValueObjectInterface
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...
17
{
18
    /** @var string */
19
    private $id;
20
21 1
    public static function fromNative($id): ValueObjectInterface
22
    {
23 1
        return new self(trim($id));
24
    }
25
26
    public static function makeEmpty(): ValueObjectInterface
27
    {
28
        throw new \Exception("Creating empty stream-ids is not supported.");
29
    }
30
31 1
    public function toNative()
32
    {
33 1
        return $this->id;
34
    }
35
36
    public function equals(ValueObjectInterface $streamId): bool
37
    {
38
        Assertion::isInstanceOf($streamId, static::class);
39
        return $this->id === $streamId->toNative();
40
    }
41
42
    public function isEmpty(): bool
43
    {
44
        return false;
45
    }
46
47
    public function __toString(): string
48
    {
49
        return $this->id;
50
    }
51
52 1
    private function __construct(string $id)
53
    {
54 1
        Assertion::notEmpty($id);
55 1
        $this->id = $id;
56 1
    }
57
}
58