Completed
Push — master ( 9a1463...3718bd )
by Basenko
04:21
created

Dispatch::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
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
    private $job;
12
13
    private $runNow;
14
15 60
    public function __construct(Command $artisanCommand, $job, bool $runNow = false)
16
    {
17 60
        parent::__construct($artisanCommand);
18
19 60
        $this->job = $job;
20 60
        $this->runNow = $runNow;
21 60
    }
22
23 60
    public function title(): string
24
    {
25 60
        return '<comment>Dispatching job:</comment> '.get_class($this->job);
26
    }
27
28 60
    public function run(): bool
29
    {
30 60
        $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...
31
32 60
        if ($this->runNow) {
33 18
            $result = Container::getInstance()->make(Dispatcher::class)->dispatchNow($this->job);
34
        } else {
35 48
            $result = Container::getInstance()->make(Dispatcher::class)->dispatch($this->job);
36
        }
37
38 60
        $artisanCommand = $this->getArtisanCommnad();
39
40 60
        if ($artisanCommand->getOutput()->isVerbose()) {
41 6
            $artisanCommand->getOutput()->newLine();
42 6
            $artisanCommand->info($result);
43
        }
44
45 60
        return ! (is_int($result) and $result > 0);
46
    }
47
}
48