Total Complexity | 5 |
Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class ProcessHandler |
||
9 | { |
||
10 | /** |
||
11 | * @var Closure $callable |
||
12 | */ |
||
13 | private Closure $callable; |
||
14 | /** |
||
15 | * @var string $label |
||
16 | */ |
||
17 | private string $label; |
||
18 | |||
19 | /** |
||
20 | * Process constructor. |
||
21 | * @param string $label |
||
22 | * @param callable $callable |
||
23 | */ |
||
24 | public function __construct(string $label, callable $callable) |
||
25 | { |
||
26 | $this->callable = $callable; |
||
27 | $this->label = $label; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return mixed |
||
32 | */ |
||
33 | public function handle() |
||
34 | { |
||
35 | return call_user_func($this->callable); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getLabel(): string |
||
42 | { |
||
43 | return $this->label; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return array |
||
48 | */ |
||
49 | public function __serialize() |
||
50 | { |
||
51 | return [ |
||
52 | 'label' => $this->label, |
||
53 | 'callable' => Serializer::closure_serialize($this->callable) |
||
54 | ]; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param array $data |
||
59 | */ |
||
60 | public function __unserialize(array $data) |
||
64 | } |
||
65 | } |
||
66 |