Completed
Pull Request — master (#11)
by
unknown
02:46
created

Callback::run()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

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