Completed
Pull Request — master (#26)
by Ruben
01:25
created

QueueableAction::onQueue()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 9.344
c 0
b 0
f 0
cc 3
nc 1
nop 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A QueueableAction.php$0 ➔ __construct() 0 5 1
A QueueableAction.php$0 ➔ execute() 0 5 1
A QueueableAction.php$0 ➔ onQueue() 0 12 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
16
            protected $queue;
17
18
            public function __construct(object $action, ?string $queue)
19
            {
20
                $this->action = $action;
21
                $this->onQueue($queue);
22
            }
23
24
            public function execute(...$parameters)
25
            {
26
                return dispatch(new ActionJob($this->action, $parameters))
27
                    ->onQueue($this->queue);
28
            }
29
30
            protected function onQueue(?string $queue): void
31
            {
32
                if (is_string($queue)) {
33
                    $this->queue = $queue;
34
35
                    return;
36
                }
37
38
                if (isset($this->action->queue)) {
39
                    $this->queue = $this->action->queue;
40
                }
41
            }
42
        };
43
44
        return $class;
45
    }
46
47
    public function tags(): array
48
    {
49
        return ['action_job'];
50
    }
51
52
    public function middleware(): array
53
    {
54
        return [];
55
    }
56
}
57