TimestampValueObject   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 35
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 6 2
A getDateTime() 0 3 1
A __construct() 0 4 1
A getValue() 0 3 1
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