Completed
Branch master (933e97)
by Torsten
04:46
created

StringId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 44
loc 44
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A fromString() 4 4 1
A toString() 4 4 1
A isEqual() 5 5 2

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
declare(strict_types=1);
4
5
namespace Lej\Component\Domain\Model;
6
7
use Assert\Assert;
8
9 View Code Duplication
class StringId implements Id
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...
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $id;
15
16
    /**
17
     * The constructor.
18
     * @param string $id
19
     */
20 7
    public function __construct(string $id)
21
    {
22 7
        Assert::that($id)->notEmpty();
23 6
        $this->id = $id;
24 6
    }
25
26
    /**
27
     * Constructs the identifier from it's string representation.
28
     * @param string $id
29
     * @return static|StringId
30
     */
31 1
    public static function fromString(string $id): StringId
32
    {
33 1
        return new static($id);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 5
    public function toString(): string
40
    {
41 5
        return $this->id;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 3
    public function isEqual(ValueObject $object): bool
48
    {
49 3
        return $object instanceof static
50 3
            && $object->toString() === $this->toString();
51
    }
52
}
53