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

Callback::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
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\Actions;
4
5
use Illuminate\Console\Command;
6
7
class Callback extends Action
8
{
9
    private $function;
10
11
    private $arguments;
12
13 12
    public function __construct(Command $artisanCommand, callable $function, array $arguments = [])
14
    {
15 12
        parent::__construct($artisanCommand);
16
17 12
        $this->function = $function;
18 12
        $this->arguments = $arguments;
19 12
    }
20
21 12
    public function title(): string
22
    {
23 12
        is_callable($this->function, false, $name);
24
25 12
        return '<comment>Calling function:</comment> '.$name;
26
    }
27
28 12
    public function run(): bool
29
    {
30 12
        if ($this->getArtisanCommnad()->getOutput()->isVerbose()) {
31 6
            $this->getArtisanCommnad()->getOutput()->newLine();
32
        }
33
34 12
        $result = call_user_func($this->function, ...$this->arguments);
35
36 12
        if (! is_bool($result) && $this->getArtisanCommnad()->getOutput()->isVerbose()) {
37 6
            $this->getArtisanCommnad()->line('<options=bold>Returned result:</>');
38 6
            $returnResult = var_export($result, true);
39 6
            $this->getArtisanCommnad()->line($returnResult);
40
        }
41
42 12
        return is_bool($result) ? $result : true;
43
    }
44
}
45