Passed
Push — master ( 373c52...ed53b1 )
by Thorsten
03:30
created

IntValue::equals()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of the daikon-cqrs/entity project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace Daikon\Entity\ValueObject;
12
13
use Daikon\Entity\Assert\Assertion;
14
15
final class IntValue implements ValueObjectInterface
16
{
17
    /**
18
     * @var int|null
19
     */
20
    private $value;
21
22
    /**
23
     * @param int|null $nativeValue
24
     * @return IntValue
25
     */
26 22
    public static function fromNative($nativeValue): IntValue
27
    {
28 22
        Assertion::nullOrInteger($nativeValue, 'Trying to create IntValue VO from unsupported value type.');
29 22
        return new static($nativeValue);
30
    }
31
32 7
    public function toNative(): ?int
33
    {
34 7
        return $this->value;
35
    }
36
37 1
    public function equals(ValueObjectInterface $value): bool
38
    {
39 1
        return $value instanceof static && $this->toNative() === $value->toNative();
40
    }
41
42 1
    public function __toString(): string
43
    {
44 1
        return is_null($this->value) ? 'null' : (string)$this->value;
45
    }
46
47 22
    private function __construct(?int $value)
48
    {
49 22
        $this->value = $value;
50 22
    }
51
}
52