AbstractValue::doHash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
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 126
    public function __construct($value)
23
    {
24 126
        $this->value = $value;
25 126
    }
26
27
    /**
28
     * @return mixed
29
     */
30 1
    public function __invoke()
31
    {
32 1
        return $this->value();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 7
    public function apply(callable $callable)
39
    {
40 7
        $value = $this->value();
41
42 7
        return $callable($value);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    abstract public function hash(): string;
49
50
    /**
51
     * @return string
52
     */
53
    abstract public function serialize();
54
55
    /**
56
     * @param string $serialized
57
     *
58
     * @return mixed
59
     */
60
    abstract public function unserialize($serialized);
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 89
    public function value()
66
    {
67 89
        return $this->value;
68
    }
69
70
    /**
71
     * @param string $string
72
     *   The string to hash
73
     *
74
     * @return string
75
     *   The string's hash
76
     */
77 28
    protected function doHash(string $string): string
78
    {
79 28
        return sha1($string);
80
    }
81
82
    /**
83
     * Set the value.
84
     *
85
     * @param mixed $value
86
     */
87 15
    protected function set($value): void
88
    {
89 15
        $this->value = $value;
90 15
    }
91
}
92