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

DateTimeObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 42
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hash() 0 4 1
A serialize() 0 6 1
A unserialize() 0 8 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