Passed
Push — master ( 819f30...8ceff2 )
by Thorsten
02:22
created

Text   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 52
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNative() 0 5 2
A equals() 0 4 2
A toNative() 0 4 1
A __toString() 0 4 1
A isEmpty() 0 4 1
A getLength() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
namespace Daikon\Entity\ValueObject;
4
5
use Daikon\Entity\Assert\Assertion;
6
7
final class Text implements ValueObjectInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private const NIL = "";
13
14
    /**
15
     * @var string
16
     */
17
    private $value;
18
19
    /**
20
     * @param string|null $nativeValue
21
     * @return self
22
     */
23 52
    public static function fromNative($nativeValue): self
24
    {
25 52
        Assertion::nullOrString($nativeValue);
26 52
        return is_null($nativeValue) ? new self : new self($nativeValue);
27
    }
28
29 5
    public function equals(ValueObjectInterface $otherValue): bool
30
    {
31 5
        return $otherValue instanceof self && $this->toNative() === $otherValue->toNative();
32
    }
33
34 29
    public function toNative(): string
35
    {
36 29
        return $this->value;
37
    }
38
39 7
    public function __toString(): string
40
    {
41 7
        return $this->toNative();
42
    }
43
44 8
    public function isEmpty(): bool
45
    {
46 8
        return $this->value === self::NIL;
47
    }
48
49 1
    public function getLength(): int
50
    {
51 1
        return strlen($this->value);
52
    }
53
54 52
    private function __construct(string $value = self::NIL)
55
    {
56 52
        $this->value = $value;
57 52
    }
58
}
59