Passed
Push — master ( d94c8e...28d464 )
by Caen
02:56 queued 12s
created

ActionCommand::action()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Hyde\Framework\Concerns;
4
5
use LaravelZero\Framework\Commands\Command;
6
7
/**
8
 * Base class for commands that run a simple action.
9
 */
10
abstract class ActionCommand extends Command
11
{
12
    protected function action(string $title, \Closure $task, $resultMessage = 'Finished')
13
    {
14
        /** @var float $actionTime */
15
        $actionTime = microtime(true);
16
17
        $this->comment("$title...");
18
19
        $result = $task();
20
21
        $this->line(" > $resultMessage in ".$this->getExecutionTimeInMs($actionTime).'ms');
22
23
        return $result;
24
    }
25
26
    protected function getExecutionTimeInMs(float $timeStart): string
27
    {
28
        return number_format(((microtime(true) - $timeStart) * 1000), 2);
29
    }
30
}
31