TypeValue   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 7
eloc 9
c 5
b 0
f 0
dl 0
loc 60
ccs 17
cts 17
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __toArray() 0 3 1
A serialize() 0 4 1
A equals() 0 3 1
A unserialize() 0 5 1
A doHash() 0 3 1
A type() 0 3 1
A hash() 0 3 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