Completed
Pull Request — master (#11)
by
unknown
02:46
created

Dispatch::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 2
1
<?php
2
3
namespace MadWeb\Initializer\Actions;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Bus\Dispatcher;
8
9
class Dispatch extends Action
10
{
11
    protected const LOADING_TEXT = 'dispatching...';
12
13
    private $job;
14
15
    private $runNow;
16
17
    public function __construct(Command $artisanCommand, $job, bool $runNow = false)
18
    {
19
        parent::__construct($artisanCommand);
20
21
        $this->job = $job;
22
        $this->runNow = $runNow;
23
    }
24
25
    public function title(): string
26
    {
27
        return '<comment>Dispatch job:</comment> '.get_class($this->job);
28
    }
29
30
    public function run(): bool
31
    {
32
        $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
        if ($this->runNow) {
35
            $result = Container::getInstance()->make(Dispatcher::class)->dispatchNow($this->job);
36
        } else {
37
            $result = Container::getInstance()->make(Dispatcher::class)->dispatch($this->job);
38
        }
39
40
        $artisanCommand = $this->getArtisanCommnad();
41
42
        if ($artisanCommand->getOutput()->isVerbose()) {
43
            $artisanCommand->getOutput()->newLine();
44
            $artisanCommand->info($result);
45
        }
46
47
        return ! (is_int($result) and $result > 0);
48
    }
49
}
50