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

Decimal::isEmpty()   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 Decimal implements ValueObjectInterface
8
{
9
    /**
10
     * @var null
11
     */
12
    private const NIL = null;
13
14
    /**
15
     * @var float
16
     */
17
    private $value;
18
19 25
    public static function fromNative($nativeValue): self
20
    {
21 25
        Assertion::nullOrFloat($nativeValue, "Trying to create value from invalid value.");
22 25
        return is_float($nativeValue) ? new static($nativeValue) : new self;
23
    }
24
25 11
    public function toNative(): ?float
26
    {
27 11
        return $this->value;
28
    }
29
30 1
    public function equals(ValueObjectInterface $otherValue): bool
31
    {
32 1
        return $otherValue instanceof self && $this->toNative() === $otherValue->toNative();
33
    }
34
35 2
    public function __toString(): string
36
    {
37 2
        return $this->value ? (string)$this->value : "null";
38
    }
39
40 25
    private function __construct(?float $value = null)
41
    {
42 25
        $this->value = $value;
43 25
    }
44
}
45