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

Artisan::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
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\ExecutorActions;
4
5
use Illuminate\Console\Command;
6
7
class Artisan
8
{
9
    private $artisanCommand;
10
11
    private $command;
12
13
    private $arguments;
14
15 66
    public function __construct(Command $artisanCommand, string $command, array $arguments = [])
16
    {
17 66
        $this->artisanCommand = $artisanCommand;
18 66
        $this->command = $command;
19 66
        $this->arguments = $arguments;
20 66
    }
21
22 66
    private function title()
23
    {
24 66
        $title = '';
0 ignored issues
show
Unused Code introduced by
$title 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...
25
26 66
        if ($this->command === 'vendor:publish') {
27 60
            $title = '<comment>Publishing resource:</comment> ';
28
29 60
            if (isset($this->arguments['--provider'])) {
30 60
                $title .= "Provider [<fg=cyan>{$this->arguments['--provider']}</>]";
31
            }
32
33
            $tagStringCallback = function (string $tag) {
34 30
                return " Tag[<fg=cyan>$tag</>]";
35 60
            };
36
37 60
            if (isset($this->arguments['--tag'])) {
38 30
                if (is_string($this->arguments['--tag'])) {
39 24
                    $title .= $tagStringCallback($this->arguments['--tag']);
40
                } else {
41 60
                    foreach ($this->arguments['--tag'] as $tag) {
42 6
                        $title .= $tagStringCallback($tag);
43
                    }
44
                }
45
            }
46
        } else {
47 6
            $title = "<comment>Running artisan command:</comment> $this->command (".
48 6
                $this->artisanCommand
49 6
                    ->getApplication()
50 6
                    ->find($this->command)
51 6
                    ->getDescription().
52 6
                ')';
53
        }
54
55 66
        return $title;
56
    }
57
58 66
    public function __invoke(): bool
59
    {
60
        return $this->artisanCommand->task($this->title(), function () {
61 66
            if ($this->artisanCommand->getOutput()->isVerbose()) {
62
                $this->artisanCommand->getOutput()->newLine();
63
64
                return ! $this->artisanCommand->call($this->command, $this->arguments);
65
            }
66
67 66
            return ! $this->artisanCommand->callSilent($this->command, $this->arguments);
68 66
        });
69
    }
70
}
71