Completed
Push — master ( acaa30...a939f2 )
by Pol
02:32
created

ObjectValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 22
ccs 2
cts 6
cp 0.3333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 8 2
A equals() 0 4 1
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