Skip to content

Commit 9cfae0a

Browse files
authored
refactor: Some minor performance & readability enhancements (#53596)
1 parent 5657af6 commit 9cfae0a

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

src/Illuminate/Bus/Dispatcher.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ public function dispatchNow($command, $handler = null)
109109
{
110110
$uses = class_uses_recursive($command);
111111

112-
if (in_array(InteractsWithQueue::class, $uses) &&
113-
in_array(Queueable::class, $uses) &&
114-
! $command->job) {
112+
if (isset($uses[InteractsWithQueue::class], $uses[Queueable::class]) && ! $command->job) {
115113
$command->setJob(new SyncJob($this->container, json_encode([]), 'sync', 'sync'));
116114
}
117115

@@ -217,7 +215,7 @@ public function dispatchToQueue($command)
217215
{
218216
$connection = $command->connection ?? null;
219217

220-
$queue = call_user_func($this->queueResolver, $connection);
218+
$queue = ($this->queueResolver)($connection);
221219

222220
if (! $queue instanceof Queue) {
223221
throw new RuntimeException('Queue resolver did not return a Queue implementation.');
@@ -239,19 +237,11 @@ public function dispatchToQueue($command)
239237
*/
240238
protected function pushCommandToQueue($queue, $command)
241239
{
242-
if (isset($command->queue, $command->delay)) {
243-
return $queue->laterOn($command->queue, $command->delay, $command);
244-
}
245-
246-
if (isset($command->queue)) {
247-
return $queue->pushOn($command->queue, $command);
248-
}
249-
250240
if (isset($command->delay)) {
251-
return $queue->later($command->delay, $command);
241+
return $queue->later($command->delay, $command, queue: $command->queue ?? null);
252242
}
253243

254-
return $queue->push($command);
244+
return $queue->push($command, queue: $command->queue ?? null);
255245
}
256246

257247
/**

tests/Bus/BusDispatcherTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testCommandsThatShouldQueueIsQueuedUsingCustomQueueAndDelay()
5151
$container = new Container;
5252
$dispatcher = new Dispatcher($container, function () {
5353
$mock = m::mock(Queue::class);
54-
$mock->shouldReceive('laterOn')->once()->with('foo', 10, m::type(BusDispatcherTestSpecificQueueAndDelayCommand::class));
54+
$mock->shouldReceive('later')->once()->with(10, m::type(BusDispatcherTestSpecificQueueAndDelayCommand::class), '', 'foo');
5555

5656
return $mock;
5757
});

0 commit comments

Comments
 (0)