Completed
Push — master ( 249adf...3f1664 )
by Pol
02:00
created

TypeValue::type()   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 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\Contract\Stringable;
9
use drupol\valuewrapper\ValueInterface;
10
11
/**
12
 * Class TypeValue
13
 */
14
abstract class TypeValue extends AbstractValue implements Stringable
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19 4
    public function hash(): string
20
    {
21 4
        return $this->doHash($this->type() . $this->value());
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 13
    public function type()
28
    {
29 13
        return \gettype($this->value());
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function equals(ValueInterface $item, $strict = true) : bool
36
    {
37 1
        return ($strict === true) ?
38 1
            $this === $item:
39 1
            $this == $item;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 6
    public function serialize()
46
    {
47 6
        return \serialize([
48 6
            'value' => $this->value(),
49
        ]);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 6
    public function unserialize($serialized)
56
    {
57 6
        $unserialize = \unserialize($serialized);
58
59 6
        $this->set($unserialize['value']);
60 6
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 4
    public function __toString(): string
66
    {
67 4
        return (string) $this->value();
68
    }
69
}
70