Completed
Push — master ( acaa30...a939f2 )
by Pol
02:32
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
declare(strict_types = 1);
4
5
namespace drupol\valuewrapper\Object;
6
7
use drupol\valuewrapper\AbstractValue;
8
use drupol\valuewrapper\Contract\Hashable;
9
use drupol\valuewrapper\ValueInterface;
10
11
/**
12
 * Class ObjectValue
13
 */
14
abstract class ObjectValue extends AbstractValue
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function hash(): string
20
    {
21
        if ($this->get() instanceof Hashable) {
22
            return $this->doHash(\gettype($this->get()) . \get_class($this->get()) . $this->get()->hash());
23
        }
24
25
        return $this->doHash(\gettype($this->get()) . \get_class($this->get()) . \spl_object_hash($this->get()));
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 2
    public function equals(ValueInterface $item, $strict = true): bool
32
    {
33 2
        return $this->hash() == $item->hash();
34
    }
35
}
36