Callback::run()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.4222
c 0
b 0
f 0
cc 5
nc 8
nop 0
crap 5
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 12
    public function __construct(Command $artisanCommand, callable $function, array $arguments = [])
16
    {
17 12
        parent::__construct($artisanCommand);
18
19 12
        $this->function = $function;
20 12
        $this->arguments = $arguments;
21 12
    }
22
23 12
    public function title(): string
24
    {
25 12
        is_callable($this->function, false, $name);
26
27 12
        return '<comment>Call function:</comment> '.$name;
28
    }
29
30 12
    public function run(): bool
31
    {
32 12
        if ($this->getArtisanCommnad()->getOutput()->isVerbose()) {
33 6
            $this->getArtisanCommnad()->getOutput()->newLine();
34
        }
35
36 12
        $result = call_user_func($this->function, ...$this->arguments);
37
38 12
        if (! is_bool($result) && $this->getArtisanCommnad()->getOutput()->isVerbose()) {
39 6
            $this->getArtisanCommnad()->line('<options=bold>Returned result:</>');
40 6
            $returnResult = var_export($result, true);
41 6
            $this->getArtisanCommnad()->line($returnResult);
42
        }
43
44 12
        return is_bool($result) ? $result : true;
45
    }
46
}
47