Completed
Push — master ( e7c2bb...340eef )
by Pol
14:36
created

ObjectValue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 33.33%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 8 2
A equals() 0 4 1
A class() 0 3 1
A type() 0 3 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(\gettype($this->value()) . \get_class($this->value()) . $this->value()->hash());
23
        }
24
25
        return $this->doHash(\gettype($this->value()) . \get_class($this->value()) . \spl_object_hash($this->value()));
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
    /**
37
     * {@inheritdoc}
38
     */
39
    public function class(): string {
0 ignored issues
show
Bug introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
40
        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...
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function type(): string {
47
        return 'object';
48
    }
49
}
50