TimestampValueObject::getValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TimiTao\ValueObject\Beberlei\Standard;
6
7
use DateTimeImmutable;
8
use Exception;
9
use TimiTao\ValueObject\Standard\DateTime\TimestampValueObject as TimestampValueObjectInterface;
10
11
abstract class TimestampValueObject implements TimestampValueObjectInterface
12
{
13
    private $value;
14
15
    /**
16
     * @throws Exception if value is invalid
17
     */
18
    public function __construct(DateTimeImmutable $value)
19
    {
20
        $this->guard($value);
21
        $this->value = $value;
22
    }
23
24
    public function getDateTime(): DateTimeImmutable
25
    {
26
        return $this->value;
27
    }
28
29
    public function equals(TimestampValueObjectInterface $other): bool
30
    {
31
        if (static::class !== get_class($other)) {
32
            return false;
33
        }
34
        return $this->getValue() === $other->getValue();
35
    }
36
37
    public function getValue(): int
38
    {
39
        return $this->value->getTimestamp();
40
    }
41
42
    /**
43
     * @throws Exception if value is invalid
44
     */
45
    abstract protected function guard(DateTimeImmutable $value): void;
46
}
47