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

Run   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 6
dl 0
loc 67
ccs 24
cts 26
cp 0.9231
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A errorMessages() 0 4 1
A run() 0 10 2
A doneWithErrors() 0 4 1
A artisan() 0 4 1
A publish() 0 4 1
A publishForce() 0 4 1
A external() 0 4 1
A callable() 0 4 1
A dispatch() 0 4 1
A dispatchNow() 0 4 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\Contracts\Runner as RunnerContract;
13
14
class Run implements RunnerContract
15
{
16
    protected $artisanCommand;
17
18
    private $errorMessages = [];
19
20 174
    public function __construct(Command $artisanCommand)
21
    {
22 174
        $this->artisanCommand = $artisanCommand;
23 174
    }
24
25 168
    public function errorMessages(): array
26
    {
27 168
        return $this->errorMessages;
28
    }
29
30 174
    private function run(Action $action)
31
    {
32 174
        $action();
33
34 168
        if ($action->failed()) {
35 12
            $this->errorMessages[] = $action->errorMessage();
36
        }
37
38 168
        return $this;
39
    }
40
41
    public function doneWithErrors(): bool
42
    {
43
        return ! empty($this->errorMessages);
44
    }
45
46 18
    public function artisan(string $command, array $arguments = []): RunnerContract
47
    {
48 18
        return $this->run(new Artisan($this->artisanCommand, $command, $arguments));
49
    }
50
51 66
    public function publish($providers, bool $force = false): RunnerContract
52
    {
53 66
        return $this->run(new Publish($this->artisanCommand, $providers, $force));
54
    }
55
56 6
    public function publishForce($providers): RunnerContract
57
    {
58 6
        return $this->publish($providers, true);
59
    }
60
61 18
    public function external(string $command, ...$arguments): RunnerContract
62
    {
63 18
        return $this->run(new External($this->artisanCommand, $command, $arguments));
64
    }
65
66 12
    public function callable(callable $function, ...$arguments): RunnerContract
67
    {
68 12
        return $this->run(new Callback($this->artisanCommand, $function, $arguments));
69
    }
70
71 48
    public function dispatch($job): RunnerContract
72
    {
73 48
        return $this->run(new Dispatch($this->artisanCommand, $job));
74
    }
75
76 18
    public function dispatchNow($job): RunnerContract
77
    {
78 18
        return $this->run(new Dispatch($this->artisanCommand, $job, true));
79
    }
80
}
81