Dispatch::title()   A
last analyzed

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\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 60
    public function __construct(Command $artisanCommand, $job, bool $runNow = false)
18
    {
19 60
        parent::__construct($artisanCommand);
20
21 60
        $this->job = $job;
22 60
        $this->runNow = $runNow;
23 60
    }
24
25 60
    public function title(): string
26
    {
27 60
        return '<comment>Dispatch job:</comment> '.get_class($this->job);
28
    }
29
30 60
    public function run(): bool
31
    {
32 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...
33
34 60
        if ($this->runNow) {
35 18
            $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 60
        $artisanCommand = $this->getArtisanCommnad();
41
42 60
        if ($artisanCommand->getOutput()->isVerbose()) {
43 6
            $artisanCommand->getOutput()->newLine();
44 6
            $artisanCommand->info($result);
45
        }
46
47 60
        return ! (is_int($result) and $result > 0);
48
    }
49
}
50