Skip to content

Commit 60b4f54

Browse files
committed
Added method for conditional execution
1 parent 73d0bd8 commit 60b4f54

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/WorkflowManager.php

+7
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88
abstract class WorkflowManager implements WorkflowInterface
99
{
1010
use WorkflowTraits;
11+
12+
protected function when(bool $condition, callable $callback)
13+
{
14+
if ($condition) {
15+
$callback();
16+
}
17+
}
1118
}

tests/Helpers/DummyWorkflow.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ public function handle(array $context)
2828

2929
$this->addAfterAction(new DummyJob());
3030

31-
if ($this->trackEvents) {
32-
$this->trackAllEvents();
33-
}
34-
35-
if ($this->registerObservers) {
31+
$this->when($this->trackEvents, fn () => $this->trackAllEvents());
32+
$this->when($this->registerObservers, function () {
3633
$this->registerObservers([
3734
DummyModel::class => DummyModelObserver::class,
3835
]);
39-
}
36+
});
4037

4138
}
4239
}

0 commit comments

Comments
 (0)