ProcessHandler::getLabel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tohidplus\Paravel\Process;
4
5
use Closure;
6
use Tohidplus\Paravel\Facades\Serializer;
7
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)
61
    {
62
        $this->label = $data['label'];
63
        $this->callable = Serializer::closure_unserialize($data['callable']);
64
    }
65
}
66