TypeValue::serialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
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\Type;
6
7
use drupol\valuewrapper\AbstractValue;
8
use drupol\valuewrapper\ValueInterface;
9
10
use function gettype;
11
12
/**
13
 * Class TypeValue.
14
 */
15
abstract class TypeValue extends AbstractValue implements TypeValueInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 5
    public function __toArray(): array
21
    {
22 5
        return (array) $this->value();
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function equals(ValueInterface $item): bool
29
    {
30 1
        return $this->value() === $item->value();
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 6
    public function hash(): string
37
    {
38 6
        return $this->doHash(var_export($this->value(), true));
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 6
    public function serialize()
45
    {
46 6
        return serialize([
47 6
            'value' => $this->value(),
48
        ]);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 13
    public function type(): string
55
    {
56 13
        return gettype($this->value());
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 6
    public function unserialize($serialized)
63
    {
64 6
        $unserialize = unserialize($serialized);
65
66 6
        $this->set($unserialize['value']);
67 6
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 7
    protected function doHash(string $string): string
73
    {
74 7
        return parent::doHash($this->type() . $string);
75
    }
76
}
77