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

AlwaysReturnStateOnFailure::onFailure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
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 AlwaysReturnStateOnFailure implements TransitionCallback
10
{
11
    /**
12
     * @var string
13
     */
14
    private $to;
15
16
    /**
17
     * @param string $to
18
     */
19
    public function __construct($to)
20
    {
21
        Assert::string($to);
22
        $this->to = $to;
23
    }
24
25
    /**
26
     * @param mixed $context
27
     * @param StateMachine $machine
28
     */
29
    public function beforeStateChange($context, StateMachine $machine)
30
    {
31
    }
32
33
    /**
34
     * @param mixed $context
35
     * @param StateMachine $machine
36
     */
37
    public function afterStateChange($context, StateMachine $machine)
38
    {
39
    }
40
41
    /**
42
     * @param InvalidStateTransitionException $exception
43
     * @param mixed $context
44
     * @param StateMachine $machine
45
     *
46
     * @return string
47
     */
48
    public function onFailure(InvalidStateTransitionException $exception, $context, StateMachine $machine)
49
    {
50
        return $this->to;
51
    }
52
}
53