Completed
Push — master ( 13b09c...acaa30 )
by Pol
02:36
created

DateTimeObject::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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