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

AnonymousObject   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 8 2
A doHash() 0 4 1
A serialize() 0 4 1
A unserialize() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace drupol\valuewrapper\Object;
6
7
use drupol\valuewrapper\Contract\Hashable;
8
9
/**
10
 * Class AnonymousObject
11
 */
12
class AnonymousObject extends ObjectValue
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 2
    public function hash(): string
18
    {
19 2
        if ($this->value() instanceof Hashable) {
20 1
            return $this->doHash($this->value()->hash());
21
        }
22
23 1
        throw new \Exception('The anonymous class must implement Hashable interface.');
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    protected function doHash(string $string) : string
30
    {
31 1
        return \sha1($string);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1
    public function serialize()
38
    {
39 1
        throw new \BadMethodCallException('Unable to serialize this class.');
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function unserialize($serialized)
46
    {
47 1
        throw new \BadMethodCallException('Unable to unserialize this class.');
48
    }
49
}
50