Completed
Push — master ( 1b2836...6cdecb )
by Pol
10:22
created

AbstractValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 75
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 4 1
A value() 0 4 1
A apply() 0 6 1
serialize() 0 1 ?
unserialize() 0 1 ?
A doHash() 0 4 1
A set() 0 4 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 101
    public function __construct($value)
23
    {
24 101
        $this->value = $value;
25 101
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 68
    public function value()
31
    {
32 68
        return $this->value;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function __invoke()
39
    {
40 1
        return $this->value();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 7
    public function apply(callable $callable)
47
    {
48 7
        $value = $this->value();
49
50 7
        return $callable($value);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    abstract public function serialize();
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    abstract public function unserialize($serialized);
62
63
    /**
64
     * @param string $string
65
     *   The string to hash.
66
     *
67
     * @return string
68
     *   The string's hash.
69
     */
70 14
    protected function doHash(string $string) : string
71
    {
72 14
        return \sha1($string);
73
    }
74
75
    /**
76
     * Set the value.
77
     *
78
     * @param mixed $value
79
     */
80 8
    protected function set($value)
81
    {
82 8
        $this->value = $value;
83 8
    }
84
}
85