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

Integer::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 Integer implements ValueObjectInterface
8
{
9
    /**
10
     * @var null
11
     */
12
    private const NIL = null;
13
14
    /**
15
     * @var int
16
     */
17
    private $value;
18
19
    /**
20
     * @param int|null $nativeValue
21
     * @return self
22
     */
23 42
    public static function fromNative($nativeValue): self
24
    {
25 42
        Assertion::nullOrInteger($nativeValue);
26 42
        return new self($nativeValue);
27
    }
28
29 17
    public function toNative(): ?int
30
    {
31 17
        return $this->value;
32
    }
33
34 4
    public function equals(ValueObjectInterface $otherValue): bool
35
    {
36 4
        return $otherValue instanceof self && $this->toNative() === $otherValue->toNative();
37
    }
38
39 6
    public function __toString(): string
40
    {
41 6
        return $this->value === self::NIL ? "null" : (string)$this->value;
42
    }
43
44 42
    private function __construct(?int $value)
45
    {
46 42
        $this->value = $value;
47 42
    }
48
}
49