Passed
Pull Request — master (#19)
by Yannick
02:27
created

CallContextMethodOnFailure::beforeStateChange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Star\Component\State\Callbacks;
4
5
use Star\Component\State\InvalidStateTransitionException;
6
use Star\Component\State\StateMachine;
7
use Webmozart\Assert\Assert;
8
9
final class CallContextMethodOnFailure implements TransitionCallback
10
{
11
    /**
12
     * @var string
13
     */
14
    private $to;
15
16
    /**
17
     * @var string
18
     */
19
    private $method;
20
21
    /**
22
     * @var array
23
     */
24
    private $args;
25
26
    /**
27
     * @param string $to
28
     * @param string $method
29
     * @param array $args
30
     */
31 1
    public function __construct(
32
        $to,
33
        $method,
34
        array $args
35
    ) {
36 1
        $this->to = $to;
37 1
        $this->method = $method;
38 1
        $this->args = $args;
39 1
    }
40
41
    /**
42
     * @param mixed $context
43
     * @param StateMachine $machine
44
     */
45 1
    public function beforeStateChange($context, StateMachine $machine)
46
    {
47 1
    }
48
49
    /**
50
     * @param mixed $context
51
     * @param StateMachine $machine
52
     */
53 1
    public function afterStateChange($context, StateMachine $machine)
54
    {
55 1
    }
56
57
    /**
58
     * @param InvalidStateTransitionException $exception
59
     * @param mixed $context
60
     * @param StateMachine $machine
61
     *
62
     * @return string
63
     */
64 1
    public function onFailure(InvalidStateTransitionException $exception, $context, StateMachine $machine)
65
    {
66 1
        Assert::object($context);
67 1
        call_user_func_array([$context, $this->method], $this->args);
68
69 1
        return $this->to;
70
    }
71
}
72