PendingDispatch   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 10
dl 0
loc 46
rs 10
c 1
b 1
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __destruct() 0 9 1
A onQueue() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas\Jobs;
6
7
use Canvas\Contracts\Queue\QueueableJobInterface;
8
use Canvas\Queue\Queue;
9
use Phalcon\Di;
10
11
class PendingDispatch
12
{
13
    /**
14
     * The job.
15
     *
16
     * @var mixed
17
     */
18
    protected $job;
19
20
    /**
21
     * Create a new pending job dispatch.
22
     *
23
     * @param  QueueableJobInterface  $job
24
     * @return void
25
     */
26
    public function __construct(QueueableJobInterface $job)
27
    {
28
        $this->job = $job;
29
    }
30
31
    /**
32
     * Set the desired queue for the job.
33
     *
34
     * @param  string  $queue
35
     * @return $this
36
     */
37
    public function onQueue(string $queue)
38
    {
39
        $this->job->onQueue($queue);
40
        return $this;
41
    }
42
43
    /**
44
     * Handle the object's destruction.
45
     *
46
     * @return void
47
     */
48
    public function __destruct()
49
    {
50
        $jobData = [
51
            'userData' => Di::getDefault()->getUserData(),
52
            'class' => get_class($this->job),
53
            'job' => $this->job
54
        ];
55
56
        return Queue::send($this->job->queue, serialize($jobData));
0 ignored issues
show
Bug Best Practice introduced by
The expression return Canvas\Queue\Queu...e, serialize($jobData)) returns the type true which is incompatible with the documented return type void.
Loading history...
57
    }
58
}
59