Completed
Push — master ( 340eef...ea8a0d )
by Pol
14:55 queued 13:14
created

AbstractValue::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
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;
6
7
/**
8
 * Class AbstractValue
9
 */
10
abstract class AbstractValue implements ValueInterface
11
{
12
    /**
13
     * @var mixed
14
     */
15
    private $value;
16
17
    /**
18
     * AbstractValue constructor.
19
     *
20
     * @param mixed $value
21
     */
22 80
    public function __construct($value)
23
    {
24 80
        $this->value = $value;
25 80
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 53
    public function value()
31
    {
32 53
        return $this->value;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function __invoke()
39
    {
40 1
        return $this->value();
41
    }
42
43
    abstract public function serialize();
44
45
    abstract public function unserialize($serialized);
46
47
    /**
48
     * @param string $string
49
     *   The string to hash.
50
     *
51
     * @return string
52
     *   The string's hash.
53
     */
54 14
    protected function doHash(string $string) : string
55
    {
56 14
        return \sha1($string);
57
    }
58
59
    /**
60
     * Set the value.
61
     *
62
     * @param mixed $value
63
     */
64 8
    protected function set($value)
65
    {
66 8
        $this->value = $value;
67 8
    }
68
}
69