Completed
Push — master ( f6d952...557c00 )
by Pol
02:56
created

TypeValue::doHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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\Type;
6
7
use drupol\valuewrapper\AbstractValue;
8
use drupol\valuewrapper\ValueInterface;
9
10
/**
11
 * Class TypeValue
12
 */
13
abstract class TypeValue extends AbstractValue implements TypeValueInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 6
    public function hash(): string
19
    {
20 6
        return $this->doHash(var_export($this->value(), true));
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 7
    protected function doHash(string $string) : string
27
    {
28 7
        return parent::doHash($this->type() . $string);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 13
    public function type() : string
35
    {
36 13
        return \gettype($this->value());
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 1
    public function equals(ValueInterface $item, $strict = true) : bool
43
    {
44 1
        return ($strict === true) ?
45 1
            $this === $item:
46 1
            $this == $item;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 6
    public function serialize()
53
    {
54 6
        return \serialize([
55 6
            'value' => $this->value(),
56
        ]);
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 4
    public function __toString(): string
73
    {
74 4
        return (string) $this->value();
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 5
    public function __toArray(): array
81
    {
82 5
        return (array) $this->value();
83
    }
84
}
85