DateTimeObject::hash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\valuewrapper\Object;
6
7
use DateTime;
8
9
/**
10
 * Class DateTimeObject.
11
 */
12
class DateTimeObject extends ObjectValue
13
{
14
    /**
15
     * DateTimeObject constructor.
16
     *
17
     * @param DateTime $value
18
     */
19 6
    public function __construct(DateTime $value)
20
    {
21 6
        parent::__construct($value);
22 6
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 2
    public function hash(): string
28
    {
29 2
        return $this->doHash($this->type() . $this->class() . $this->value()->getTimestamp());
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function serialize()
36
    {
37 1
        return serialize([
38 1
            'value' => $this->value()->getTimestamp(),
39
        ]);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function unserialize($serialized)
46
    {
47 1
        $unserialize = unserialize($serialized);
48
49 1
        $this->set(
50 1
            (new DateTime())->setTimestamp($unserialize['value'])
51
        );
52 1
    }
53
}
54