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

AnonymousObject::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\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