Skip to content

Commit c4e2547

Browse files
committed
wip
1 parent 4eb7509 commit c4e2547

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/Machinery.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ trait Machinery
66
{
77
public function transitionTo($machineKey, MachineryState $state, ?callable $sideEffect = null): MachineryState
88
{
9-
$sideEffect = $sideEffect ?? fn () => null;
9+
if (!$this->canTransitionTo($machineKey, $state)) {
10+
throw new InvalidStateTransition("Cannot transition from state [{$this->{$machineKey}->value}] to state [{$state->value}].");
11+
}
1012

11-
$callable = function () use ($state, $machineKey, $sideEffect) {
12-
$sideEffect($this);
13-
$this->$machineKey = $state;
14-
$this->save();
15-
};
13+
($sideEffect ?? fn() => null)($this);
1614

17-
return $this->{$machineKey}->transitionTo($state, $callable);
15+
$this->$machineKey = $state;
16+
$this->save();
17+
18+
return $state;
1819
}
1920

2021
public function canTransitionTo($machineKey, MachineryState $state): bool

src/MachineryEnumeration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ trait MachineryEnumeration
1212
*/
1313
public function transitionTo(MachineryState $state, ?callable $sideEffect = null): MachineryState
1414
{
15-
1615
if (!$this->canTransitionTo($state)) {
1716
throw new InvalidStateTransition("Cannot transition from state [{$this->value}] to state [{$state->value}].");
1817
}

0 commit comments

Comments
 (0)