Completed
Branch master (c4a11b)
by Adrian Florin
10:27 queued 07:46
created

Process::putResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
namespace NeedleProject\Transaction;
3
4
/**
5
 * Class Process
6
 *
7
 * @package NeedleProject\Transaction
8
 * @author  Adrian Tilita <[email protected]>
9
 */
10
class Process implements ProcessInterface, ExecutionResultInterface, RollBackResultInterface
11
{
12
    use ExecutionResultTrait;
13
    use RollBackResultTrait;
14
    use ExecutionStateTrait;
15
16
    /**
17
     * @var null|\Closure
18
     */
19
    private $executeAction = null;
20
21
    /**
22
     * @var null|\Closure
23
     */
24
    private $rollbackAction = null;
25
26
    /**
27
     * @var string
28
     */
29
    private $processName = null;
30
31
    /**
32
     * Process constructor.
33
     *
34
     * @param \Closure $executeAction
35
     * @param \Closure $rollbackAction
36
     * @param string $processName
37
     */
38 9
    public function __construct(\Closure $executeAction, \Closure $rollbackAction, string $processName = null)
39
    {
40 9
        if (is_null($processName)) {
41 6
            $processName = spl_object_hash($executeAction) . '_' . spl_object_hash($rollbackAction);
42
        }
43 9
        $this->executeAction = $executeAction;
44 9
        $this->rollbackAction = $rollbackAction;
45 9
        $this->processName = $processName;
46 9
    }
47
48
    /**
49
     * @return string
50
     */
51 2
    public function getName(): string
52
    {
53 2
        return $this->processName;
54
    }
55
56
    /**
57
     * Execute the process
58
     */
59 5
    public function execute()
60
    {
61 5
        return $this->executeAction->__invoke();
62
    }
63
64
    /**
65
     * Rollback action
66
     */
67 2
    public function rollBack()
68
    {
69 2
        return $this->rollbackAction->__invoke();
70
    }
71
}
72