Completed
Pull Request — master (#11)
by
unknown
14:45
created

Run::doneWithErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
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;
4
5
use Illuminate\Console\Command;
6
use MadWeb\Initializer\Actions\Action;
7
use MadWeb\Initializer\Actions\Artisan;
8
use MadWeb\Initializer\Actions\Callback;
9
use MadWeb\Initializer\Actions\Dispatch;
10
use MadWeb\Initializer\Actions\External;
11
use MadWeb\Initializer\Actions\Publish;
12
use MadWeb\Initializer\Actions\PublishTag;
13
use MadWeb\Initializer\Contracts\Runner as RunnerContract;
14
15
class Run implements RunnerContract
16
{
17
    protected $artisanCommand;
18
19
    protected $options;
20
21 204
    private $errorMessages = [];
22
23 204
    public function __construct(Command $artisanCommand)
24 204
    {
25
        $this->artisanCommand = $artisanCommand;
26 192
        $this->options = $artisanCommand->option('options');
27
    }
28 192
29
    public function errorMessages(): array
30
    {
31 204
        return $this->errorMessages;
32
    }
33 204
34
    private function run(Action $action)
35 192
    {
36 12
        $action();
37
38
        if ($action->failed()) {
39 192
            $this->errorMessages[] = $action->errorMessage();
40
        }
41
42
        return $this;
43
    }
44
45
    public function doneWithErrors(): bool
46
    {
47 18
        return ! empty($this->errorMessages);
48
    }
49 18
50
    public function artisan(string $command, array $arguments = []): RunnerContract
51
    {
52 72
        return $this->run(new Artisan($this->artisanCommand, $command, $arguments));
53
    }
54 72
55
    public function publish($providers, bool $force = false): RunnerContract
56
    {
57 6
        return $this->run(new Publish($this->artisanCommand, $providers, $force));
58
    }
59 6
60
    public function publishForce($providers): RunnerContract
61
    {
62 24
        return $this->publish($providers, true);
63
    }
64 24
65
    public function publishTag($tag, bool $force = false): RunnerContract
66
    {
67 12
        return $this->run(new PublishTag($this->artisanCommand, $tag, $force));
68
    }
69 12
70
    public function publishTagForce($tag): RunnerContract
71
    {
72 18
        return $this->publishTag($tag, true);
73
    }
74 18
75
    public function external(string $command, ...$arguments): RunnerContract
76
    {
77 12
        return $this->run(new External($this->artisanCommand, $command, $arguments));
78
    }
79 12
80
    public function callable(callable $function, ...$arguments): RunnerContract
81
    {
82 48
        return $this->run(new Callback($this->artisanCommand, $function, $arguments));
83
    }
84 48
85
    public function dispatch($job): RunnerContract
86
    {
87 18
        return $this->run(new Dispatch($this->artisanCommand, $job));
88
    }
89 18
90
    public function dispatchNow($job): RunnerContract
91
    {
92
        return $this->run(new Dispatch($this->artisanCommand, $job, true));
93
    }
94
95
    public function getOption(string $option): bool
96
    {
97
        return in_array($option, $this->options);
98
    }
99
}
100