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

Text::makeEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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