1 | <?php declare(strict_types=1); |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
2 | |||
3 | namespace Star\Component\State\Callbacks; |
||
4 | |||
5 | use Star\Component\State\InvalidStateTransitionException; |
||
6 | use Star\Component\State\StateMachine; |
||
7 | |||
8 | final class CallClosureOnFailure implements TransitionCallback |
||
0 ignored issues
–
show
|
|||
9 | { |
||
0 ignored issues
–
show
|
|||
10 | /** |
||
0 ignored issues
–
show
|
|||
11 | * @var \Closure |
||
12 | */ |
||
13 | private $callback; |
||
0 ignored issues
–
show
|
|||
14 | |||
15 | 1 | public function __construct(\Closure $callback) |
|
0 ignored issues
–
show
|
|||
16 | { |
||
0 ignored issues
–
show
|
|||
17 | 1 | $this->callback = $callback; |
|
18 | 1 | } |
|
0 ignored issues
–
show
|
|||
19 | |||
20 | /** |
||
0 ignored issues
–
show
|
|||
21 | * @param mixed $context |
||
0 ignored issues
–
show
|
|||
22 | * @param StateMachine $machine |
||
0 ignored issues
–
show
|
|||
23 | */ |
||
0 ignored issues
–
show
|
|||
24 | 1 | public function beforeStateChange($context, StateMachine $machine): void |
|
25 | { |
||
0 ignored issues
–
show
|
|||
26 | 1 | } |
|
0 ignored issues
–
show
|
|||
27 | |||
28 | /** |
||
0 ignored issues
–
show
|
|||
29 | * @param mixed $context |
||
0 ignored issues
–
show
|
|||
30 | * @param StateMachine $machine |
||
0 ignored issues
–
show
|
|||
31 | */ |
||
0 ignored issues
–
show
|
|||
32 | 1 | public function afterStateChange($context, StateMachine $machine): void |
|
33 | { |
||
0 ignored issues
–
show
|
|||
34 | 1 | } |
|
0 ignored issues
–
show
|
|||
35 | |||
36 | /** |
||
0 ignored issues
–
show
|
|||
37 | * @param InvalidStateTransitionException $exception |
||
0 ignored issues
–
show
|
|||
38 | * @param mixed $context |
||
0 ignored issues
–
show
|
|||
39 | * @param StateMachine $machine |
||
0 ignored issues
–
show
|
|||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | 1 | public function onFailure(InvalidStateTransitionException $exception, $context, StateMachine $machine): string |
|
0 ignored issues
–
show
|
|||
44 | { |
||
0 ignored issues
–
show
|
|||
45 | 1 | $callback = $this->callback; |
|
46 | |||
47 | 1 | return $callback($context); |
|
48 | } |
||
0 ignored issues
–
show
|
|||
49 | } |
||
0 ignored issues
–
show
|
|||
50 |