Completed
Push — master ( 6b5da6...9a1463 )
by Basenko
04:09
created

Dispatch::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace MadWeb\Initializer\ExecutorActions;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Bus\Dispatcher;
8
9
class Dispatch
10
{
11
    private $artisanCommand;
12
13
    private $job;
14
15
    private $runNow;
16
17 54
    public function __construct(Command $artisanCommand, $job, bool $runNow = false)
18
    {
19 54
        $this->artisanCommand = $artisanCommand;
20 54
        $this->job = $job;
21 54
        $this->runNow = $runNow;
22 54
    }
23
24 54
    private function title()
25
    {
26 54
        return '<comment>Dispatching job:</comment> '.get_class($this->job);
27
    }
28
29 54
    public function __invoke(): bool
30
    {
31
        return $this->artisanCommand->task($this->title(), function () {
32 54
            $result = null;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
34 54
            if ($this->runNow) {
35 12
                $result = Container::getInstance()->make(Dispatcher::class)->dispatchNow($this->job);
36
            } else {
37 48
                $result = Container::getInstance()->make(Dispatcher::class)->dispatch($this->job);
38
            }
39
40 54
            if ($this->artisanCommand->getOutput()->isVerbose()) {
41
                $this->artisanCommand->getOutput()->newLine();
42
                $this->artisanCommand->info($result);
43
            }
44 54
        });
45
    }
46
}
47