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

Decimal   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromNative() 0 5 2
A toNative() 0 4 1
A equals() 0 4 2
A __toString() 0 4 2
A __construct() 0 4 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