Completed
Push — master ( 3718bd...016efe )
by Basenko
03:23
created

Run::callable()   A

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 2
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
    private $errorMessages = [];
20
21 204
    public function __construct(Command $artisanCommand)
22
    {
23 204
        $this->artisanCommand = $artisanCommand;
24 204
    }
25
26 192
    public function errorMessages(): array
27
    {
28 192
        return $this->errorMessages;
29
    }
30
31 204
    private function run(Action $action)
32
    {
33 204
        $action();
34
35 192
        if ($action->failed()) {
36 12
            $this->errorMessages[] = $action->errorMessage();
37
        }
38
39 192
        return $this;
40
    }
41
42
    public function doneWithErrors(): bool
43
    {
44
        return ! empty($this->errorMessages);
45
    }
46
47 18
    public function artisan(string $command, array $arguments = []): RunnerContract
48
    {
49 18
        return $this->run(new Artisan($this->artisanCommand, $command, $arguments));
50
    }
51
52 72
    public function publish($providers, bool $force = false): RunnerContract
53
    {
54 72
        return $this->run(new Publish($this->artisanCommand, $providers, $force));
55
    }
56
57 6
    public function publishForce($providers): RunnerContract
58
    {
59 6
        return $this->publish($providers, true);
60
    }
61
62 24
    public function publishTag($tag, bool $force = false): RunnerContract
63
    {
64 24
        return $this->run(new PublishTag($this->artisanCommand, $tag, $force));
65
    }
66
67 12
    public function publishTagForce($tag): RunnerContract
68
    {
69 12
        return $this->publishTag($tag, true);
70
    }
71
72 18
    public function external(string $command, ...$arguments): RunnerContract
73
    {
74 18
        return $this->run(new External($this->artisanCommand, $command, $arguments));
75
    }
76
77 12
    public function callable(callable $function, ...$arguments): RunnerContract
78
    {
79 12
        return $this->run(new Callback($this->artisanCommand, $function, $arguments));
80
    }
81
82 48
    public function dispatch($job): RunnerContract
83
    {
84 48
        return $this->run(new Dispatch($this->artisanCommand, $job));
85
    }
86
87 18
    public function dispatchNow($job): RunnerContract
88
    {
89 18
        return $this->run(new Dispatch($this->artisanCommand, $job, true));
90
    }
91
}
92