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

ObjectValue::hash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace drupol\valuewrapper\Object;
4
5
use drupol\valuewrapper\AbstractValue;
6
use drupol\valuewrapper\Hashable;
7
8
/**
9
 * Class ObjectValue
10
 */
11
class ObjectValue extends AbstractValue
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function hash(): string
17
    {
18
        if ($this->value instanceof Hashable) {
19
            return $this->doHash(gettype($this->value) . get_class($this->value) . $this->value->hash());
20
        }
21
22
        return $this->doHash(gettype($this->value) . get_class($this->value) . \spl_object_hash($this->value));
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 3
    protected function doHash(string $string) : string
29
    {
30 3
        return \sha1($string);
31
    }
32
}
33