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

Action   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 50
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 16 2
A failed() 0 4 1
A errorMessage() 0 4 1
title() 0 1 ?
run() 0 1 ?
A getArtisanCommnad() 0 4 1
1
<?php
2
3
namespace MadWeb\Initializer\Actions;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
8
abstract class Action
9
{
10
    /** @var \Illuminate\Console\Command */
11
    private $artisanCommnad;
12
13
    private $failed = false;
14
15
    protected $errorMessage = null;
16
17 174
    public function __construct(Command $artisanCommnad)
18
    {
19 174
        $this->artisanCommnad = $artisanCommnad;
20 174
    }
21
22 168
    public function __invoke(): bool
23
    {
24
        $failed = ! $this->getArtisanCommnad()->task($this->title(), function () {
25
            try {
26 168
                return $this->run();
27 12
            } catch (Exception $e) {
28 12
                $this->errorMessage = get_class($e).': '.$e->getMessage();
29
30 12
                return false;
31
            }
32 168
        });
33
34 168
        $this->failed = $failed;
35
36 168
        return ! $failed;
37
    }
38
39 168
    public function failed(): bool
40
    {
41 168
        return $this->failed;
42
    }
43
44 12
    public function errorMessage(): string
45
    {
46 12
        return $this->errorMessage;
47
    }
48
49
    abstract public function title(): string;
50
51
    abstract public function run(): bool;
52
53 168
    public function getArtisanCommnad(): Command
54
    {
55 168
        return $this->artisanCommnad;
56
    }
57
}
58