Skip to content

Commit f9ba1a8

Browse files
committed
Edge case for $current being empty, handled
1 parent 017e5cc commit f9ba1a8

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

src/CommandBus/CommandBus.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __invoke(Command $command, callable $next = null)
3434
$middleware = $this->middleware;
3535
$current = array_shift($middleware);
3636

37-
if (empty($middleware)) {
37+
if (empty($middleware) && !empty($current)) {
3838
$current->__invoke($command);
3939
return;
4040
}
@@ -47,6 +47,5 @@ public function __invoke(Command $command, callable $next = null)
4747
$current->__invoke($command, $callable);
4848
$current = $commandBusMiddleware;
4949
}
50-
unset($middleware);
5150
}
5251
}

src/EventBus/EventBus.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public function __invoke(Event $event, callable $next = null)
3737
$middleware = $this->middleware;
3838
$current = array_shift($middleware);
3939

40-
if (empty($middleware)) {
40+
if (empty($middleware) && !empty($current)) {
4141
$current->__invoke($event);
4242
return;
4343
}
44-
44+
4545
foreach ($middleware as $eventBusMiddleware) {
4646
$callable = function ($event) use ($eventBusMiddleware) {
4747
return $eventBusMiddleware($event);
@@ -50,6 +50,5 @@ public function __invoke(Event $event, callable $next = null)
5050
$current->__invoke($event, $callable);
5151
$current = $eventBusMiddleware;
5252
}
53-
unset($middleware);
5453
}
5554
}

0 commit comments

Comments
 (0)