Completed
Push — master ( 7a93ab...e5b266 )
by Michael
03:59
created

Command   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
run() 0 1 ?
A __invoke() 0 10 2
A echo() 0 11 2
A echoError() 0 4 1
A echoInfo() 0 4 1
A echoNotes() 0 6 2
1
<?php
2
3
namespace Schnittstabil\Dartisan\Commands;
4
5
use Garden\Cli\Cli;
6
use Garden\Cli\Args;
7
use Illuminate\Database\Migrations\Migrator;
8
9
abstract class Command
10
{
11
    protected $outputFormatter;
12
13
    public function __construct(callable $outputFormatter)
14
    {
15
        $this->outputFormatter = $outputFormatter;
16
    }
17
18
    abstract protected function run();
19
20
    public function __invoke()
21
    {
22
        try {
23
            return $this->run();
24
        } catch(\Exception $e) {
25
            $this->echoError($e);
26
            
27
            return 2;
28
        }
29
    }
30
31
    protected function echo($msg, bool $eol = true)
32
    {
33
        $outputFormatter = $this->outputFormatter;
34
        $output = $outputFormatter($msg);
35
36
        if ($eol) {
37
            $output .= PHP_EOL;
38
        }
39
        
40
        echo $output;
41
    }
42
43
    protected function echoError($msg, bool $eol = true)
44
    {
45
        $this->echo('<error>'.$msg.'</error>', $eol);
46
    }
47
48
    protected function echoInfo($msg, bool $eol = true)
49
    {
50
        $this->echo('<info>'.$msg.'</info>', $eol);
51
    }
52
53
    protected function echoNotes($notes)
54
    {
55
        foreach ($notes as $note) {
56
            $this->echo($note);
57
        }
58
    }
59
}
60