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

TypeValue::serialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\valuewrapper\Type;
6
7
use drupol\valuewrapper\AbstractValue;
8
use drupol\valuewrapper\ValueInterface;
9
10
/**
11
 * Class TypeValue
12
 */
13
abstract class TypeValue extends AbstractValue
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 4
    public function hash(): string
19
    {
20 4
        return $this->doHash($this->getType() . $this->get());
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 13
    public function getType()
27
    {
28 13
        return \gettype($this->get());
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 1
    public function equals(ValueInterface $item, $strict = true) : bool
35
    {
36 1
        return ($strict === true) ?
37 1
            $this === $item:
38 1
            $this == $item;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 6
    public function serialize()
45
    {
46 6
        return \serialize([
47 6
            'value' => $this->get(),
48
        ]);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 6
    public function unserialize($serialized)
55
    {
56 6
        $unserialize = \unserialize($serialized);
57
58 6
        $this->set($unserialize['value']);
59 6
    }
60
}
61