Completed
Push — master ( 6b5da6...9a1463 )
by Basenko
04:09
created

Callback::__invoke()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.9332
c 0
b 0
f 0
cc 2
nc 1
nop 0
crap 2.032
1
<?php
2
3
namespace MadWeb\Initializer\ExecutorActions;
4
5
use Illuminate\Console\Command;
6
7
class Callback
8
{
9
    private $artisanCommand;
10
11
    private $function;
12
13
    private $arguments;
14
15 6
    public function __construct(Command $artisanCommand, callable $function, array $arguments = [])
16
    {
17 6
        $this->artisanCommand = $artisanCommand;
18 6
        $this->function = $function;
19 6
        $this->arguments = $arguments;
20 6
    }
21
22 6
    private function title()
23
    {
24 6
        is_callable($this->function, false, $name);
25
26 6
        return '<comment>Calling function:</comment> '.$name;
27
    }
28
29 6
    public function __invoke(): bool
30
    {
31
        return $this->artisanCommand->task($this->title(), function () {
32 6
            if ($this->artisanCommand->getOutput()->isVerbose()) {
33
                $this->artisanCommand->getOutput()->newLine();
34
            }
35
36 6
            return call_user_func($this->function, ...$this->arguments);
37 6
        });
38
    }
39
}
40