Completed
Push — master ( 2a1736...a76588 )
by Pol
03:14 queued 01:51
created

ClosureObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
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 __construct() 0 4 1
A hash() 0 6 1
A __invoke() 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\ValueInterface;
8
use SuperClosure\Serializer;
9
10
/**
11
 * Class ClosureObject
12
 */
13
class ClosureObject extends ObjectValue
14
{
15
    /**
16
     * ClosureObject constructor.
17
     *
18
     * @param \Closure $value
19
     */
20 5
    public function __construct(\Closure $value)
21
    {
22 5
        parent::__construct($value);
23 5
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function hash(): string
29
    {
30 2
        $serializer = new Serializer();
31
32 2
        return $this->doHash($serializer->serialize($this->get()));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function __invoke()
39
    {
40 1
        return \call_user_func_array($this->get(), \func_get_args());
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function equals(ValueInterface $item, $strict = true): bool
47
    {
48 1
        return $this->hash() == $item->hash();
49
    }
50
}
51