QueueableAction   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 46
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ __construct() 0 5 1
A hp$0 ➔ execute() 0 5 1
A hp$0 ➔ onQueue() 0 12 3
A onQueue() 0 35 3
A tags() 0 4 1
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
    public function tags(): array
47
    {
48
        return ['action_job'];
49
    }
50
}
51