Completed
Push — master ( a76588...627495 )
by Pol
02:01
created

ObjectValue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 30
ccs 4
cts 8
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 8 2
A doHash() 0 4 1
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 4
    protected function doHash(string $string) : string
32
    {
33 4
        return \sha1($string);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 1
    public function equals(ValueInterface $item, $strict = true): bool
40
    {
41 1
        return $this->hash() == $item->hash();
42
    }
43
}
44