Completed
Push — master ( 2a1736...a76588 )
by Pol
03:14 queued 01:51
created

AbstractValue::doHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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 46
    public function __construct($value)
23
    {
24 46
        $this->value = $value;
25 46
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 25
    public function get()
31
    {
32 25
        return $this->value;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function equals(ValueInterface $item, $strict = true) : bool
39
    {
40
        return ($strict === true) ?
41
            $this === $item:
42
            $this == $item;
43
    }
44
45
    /**
46
     * @param string $string
47
     *   The string to hash.
48
     *
49
     * @return string
50
     *   The string's hash.
51
     */
52 8
    protected function doHash(string $string) : string
53
    {
54 8
        return \sha1($string);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function __invoke()
61
    {
62
        return $this->get();
63
    }
64
}
65