Completed
Pull Request — master (#13)
by
unknown
59s
created

ActionJob::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Spatie\QueueableAction;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Queue\InteractsWithQueue;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Foundation\Bus\Dispatchable;
10
11
class ActionJob implements ShouldQueue
12
{
13
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
14
15
    /** @var string */
16
    protected $actionClass;
17
18
    /** @var array */
19
    protected $parameters;
20
21
    public function __construct($action, array $parameters = [])
22
    {
23
        $this->actionClass = is_string($action) ? $action : get_class($action);
24
        $this->parameters = $parameters;
25
26
        $this->resolveQueueableProperties($action);
27
    }
28
29
    public function displayName(): string
30
    {
31
        return $this->actionClass;
32
    }
33
34
    public function tags()
35
    {
36
        return ['action_job'];
37
    }
38
39
    public function handle()
40
    {
41
        $action = app($this->actionClass);
42
43
        $action->execute(...$this->parameters);
44
    }
45
46
    protected function resolveQueueableProperties($action)
47
    {
48
        $queueableProperties = [
49
            'connection',
50
            'queue',
51
            'chainConnection',
52
            'chainQueue',
53
            'delay',
54
            'chained',
55
            'tries',
56
            'timeout',
57
        ];
58
59
        foreach ($queueableProperties as $queueableProperty) {
60
            if(property_exists($action, $queueableProperty) {
61
                $this->{$queueableProperty} = $action->{$queueableProperty};   
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ';'
Loading history...
62
            }
63
        }
64
    }
65
}
66