Completed
Push — master ( 3542dd...198cad )
by Pol
05:51
created

ObjectValue::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\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 implements ObjectValueInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function hash(): string
20
    {
21
        if ($this->value() instanceof Hashable) {
22
            return $this->doHash($this->value()->hash());
23
        }
24
25
        return $this->doHash(\spl_object_hash($this->value()));
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 4
    protected function doHash(string $string) : string
32
    {
33 4
        return parent::doHash($this->type() . $this->class() . $string);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function equals(ValueInterface $item, $strict = true): bool
40
    {
41 2
        return $this->hash() == $item->hash();
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function class(): string
0 ignored issues
show
Bug introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
48
    {
49
        return \get_class($this->value());
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 4
    public function type(): string
56
    {
57 4
        return 'object';
58
    }
59
}
60