DispatchesJobs::runInQueue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 4
crap 1
1
<?php
2
3
namespace Anfischer\Foundation\Job\Concerns;
4
5
use Anfischer\Foundation\Job\Job;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Collection;
8
9
trait DispatchesJobs
10
{
11
    /**
12
     * Beautifier function to be called instead of the
13
     * laravel function dispatch.
14
     *
15
     * @param mixed                          $job
16
     * @param array|\Illuminate\Http\Request $arguments
17
     * @param array                          $extra
18
     *
19
     * @return mixed
20
     */
21 12
    public function run($job, $arguments = [], array $extra = [])
22
    {
23 12
        return $this->dispatch($this->prepare($job, $arguments, $extra));
0 ignored issues
show
Bug introduced by
It seems like dispatch() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        return $this->/** @scrutinizer ignore-call */ dispatch($this->prepare($job, $arguments, $extra));
Loading history...
24
    }
25
26
    /**
27
     * Runs the job in the given queue.
28
     *
29
     * @param string $job
30
     * @param array|\Illuminate\Http\Request $arguments
31
     * @param array $extra
32
     * @param string $queue
33
     *
34
     * @return mixed
35
     */
36 6
    public function runInQueue($job, $arguments = [], array $extra = [], string $queue = 'default')
37
    {
38 6
        $job = $this->prepare($job, $arguments, $extra);
39 6
        $job->onQueue($queue);
0 ignored issues
show
Bug introduced by
The method onQueue() does not exist on Anfischer\Foundation\Job\Job. It seems like you code against a sub-type of Anfischer\Foundation\Job\Job such as Anfischer\Foundation\Job\QueueableJob. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        $job->/** @scrutinizer ignore-call */ 
40
              onQueue($queue);
Loading history...
40
41 6
        return $this->dispatch($job);
42
    }
43
44
45
    /**
46
     * Prepare a job by marshalling it if needed.
47
     *
48
     * @param $job
49
     * @param $arguments
50
     * @param array $extra
51
     * @return mixed
52
     */
53 18
    private function prepare($job, $arguments, array $extra) : Job
54
    {
55 18
        if ($arguments instanceof Request) {
56 6
            return $this->marshal($job, $arguments, $extra);
0 ignored issues
show
Bug introduced by
It seems like marshal() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            return $this->/** @scrutinizer ignore-call */ marshal($job, $arguments, $extra);
Loading history...
57
        }
58
59 12
        if (! \is_object($job)) {
60 6
            return $this->marshal($job, new Collection($arguments), $extra);
61
        }
62
63 6
        return $job;
64
    }
65
}
66