Completed
Push — master ( 031b8d...7e4269 )
by Freek
25s queued 10s
created

QueueableAction.php$0 ➔ onQueue()   A

Complexity

Conditions 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 3
1
<?php
2
3
namespace Spatie\QueueableAction;
4
5
trait QueueableAction
6
{
7
    /**
8
     * @return static
9
     */
10
    public function onQueue(?string $queue = null)
11
    {
12
        /** @var self $class */
13
        $class = new class($this, $queue) {
14
            protected $action;
15
            protected $queue;
16
17
            public function __construct(object $action, ?string $queue)
18
            {
19
                $this->action = $action;
20
                $this->onQueue($queue);
21
            }
22
23
            public function execute(...$parameters)
24
            {
25
                return dispatch(new ActionJob($this->action, $parameters))
26
                    ->onQueue($this->queue);
27
            }
28
29
            protected function onQueue(?string $queue): void
30
            {
31
                if (is_string($queue)) {
32
                    $this->queue = $queue;
33
34
                    return;
35
                }
36
37
                if (isset($this->action->queue)) {
38
                    $this->queue = $this->action->queue;
39
                }
40
            }
41
        };
42
43
        return $class;
44
    }
45
}
46