Completed
Push — master ( e238c3...0855a3 )
by Pol
13:48 queued 01:17
created

AbstractValue   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 38.46%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 55
ccs 5
cts 13
cp 0.3846
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
A equals() 0 6 2
A doHash() 0 4 1
A __invoke() 0 4 1
1
<?php
2
3
namespace drupol\valuewrapper;
4
5
/**
6
 * Class AbstractValue
7
 */
8
abstract class AbstractValue implements ValueInterface
9
{
10
    /**
11
     * @var mixed
12
     */
13
    protected $value;
14
15
    /**
16
     * AbstractValue constructor.
17
     *
18
     * @param mixed $value
19
     */
20 23
    public function __construct($value)
21
    {
22 23
        $this->value = $value;
23 23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function get()
29
    {
30 1
        return $this->value;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function equals(ValueInterface $item, $strict = true) : bool
37
    {
38
        return ($strict === true) ?
39
            $this === $item:
40
            $this == $item;
41
    }
42
43
    /**
44
     * @param string $string
45
     *   The string to hash.
46
     *
47
     * @return string
48
     *   The string's hash.
49
     */
50
    protected function doHash(string $string) : string
51
    {
52
        return \sha1($string);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function __invoke()
59
    {
60
        return $this->value;
61
    }
62
}
63