Completed
Push — master ( 144561...579d36 )
by Christopher
02:57
created

CallbackTask   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 90.48%

Importance

Changes 7
Bugs 1 Features 2
Metric Value
c 7
b 1
f 2
dl 0
loc 92
wmc 8
lcom 1
cbo 1
ccs 19
cts 21
cp 0.9048
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serialize() 0 6 1
A unserialize() 0 7 1
A getData() 0 6 1
A getHandler() 0 4 1
A ignoresRules() 0 4 1
A stopsSiblings() 0 4 1
A canRunTask() 0 4 1
1
<?php
2
3
namespace AsyncPHP\Doorman\Task;
4
5
use AsyncPHP\Doorman\Task;
6
use Closure;
7
use SuperClosure\SerializableClosure;
8
9
class CallbackTask implements Task
10
{
11
    /**
12
     * @var Closure
13
     */
14
    private $closure;
15
16
    /**
17
     * @param Closure $closure
18
     */
19 3
    public function __construct(Closure $closure)
20
    {
21 3
        $this->closure = $closure;
22 3
    }
23
24
    /**
25
     * @inheritdoc
26
     *
27
     * @return string
28
     */
29 1
    public function serialize()
30
    {
31 1
        $closure = new SerializableClosure($this->closure);
32
33 1
        return serialize($closure);
34
    }
35
36
    /**
37
     * @inheritdoc
38
     *
39
     * @param string $serialized
40
     */
41 1
    public function unserialize($serialized)
42
    {
43
        /** @var SerializableClosure $closure */
44 1
        $closure = unserialize($serialized);
45
46 1
        $this->closure = $closure->getClosure();
47 1
    }
48
49
    /**
50
     * @inheritdoc
51
     *
52
     * @return array
53
     */
54 1
    public function getData()
55
    {
56
        return [
57 1
            "closure" => $this->closure,
58 1
        ];
59
    }
60
61
    /**
62
     * @inheritdoc
63
     *
64
     * @return string
65
     */
66 1
    public function getHandler()
67
    {
68 1
        return "AsyncPHP\\Doorman\\Handler\\CallbackHandler";
69
    }
70
71
    /**
72
     * @inheritdoc
73
     *
74
     * @return bool
75
     */
76 1
    public function ignoresRules()
77
    {
78 1
        return false;
79
    }
80
81
    /**
82
     * @inheritdoc
83
     *
84
     * @return bool
85
     */
86 1
    public function stopsSiblings()
87
    {
88 1
        return false;
89
    }
90
91
    /**
92
     * @inheritdoc
93
     *
94
     * @return bool
95
     */
96
    public function canRunTask()
97
    {
98
        return true;
99
    }
100
}
101