Passed
Push — master ( 214e16...a05e52 )
by Caen
03:13 queued 12s
created

ValidateCommand::runCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Console\Commands;
6
7
use Hyde\Framework\Concerns\TracksExecutionTime;
8
use Hyde\Framework\Services\ValidationService;
9
use LaravelZero\Framework\Commands\Command;
10
11
/**
12
 * @see \Hyde\Framework\Testing\Feature\Commands\ValidateCommandTest
13
 */
14
class ValidateCommand extends Command
15
{
16
    use TracksExecutionTime;
17
18
    /** @var string */
19
    protected $signature = 'validate';
20
21
    /** @var string */
22
    protected $description = 'Run a series of tests to validate your setup and help you optimize your site.';
23
24
    protected ValidationService $service;
25
26
    public function __construct()
27
    {
28
        parent::__construct();
29
30
        $this->service = new ValidationService();
31
    }
32
33
    public function handle(): int
34
    {
35
        $this->startClock();
36
37
        $this->info('Running validation tests!');
38
39
        $this->newLine();
40
41
        foreach (ValidationService::checks() as $check) {
42
            $this->runCheck($check);
43
        }
44
45
        $this->info("All done! {$this->timeTotal()}");
46
47
        return Command::SUCCESS;
48
    }
49
50
    protected function runCheck(string $check): void
51
    {
52
        $timeStart = microtime(true);
53
        $result = $this->service->run($check);
54
55
        $this->line($result->formattedMessage($this->getCheckTime($timeStart)));
0 ignored issues
show
Bug introduced by
It seems like $timeStart can also be of type string; however, parameter $timeStart of Hyde\Console\Commands\Va...Command::getCheckTime() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
        $this->line($result->formattedMessage($this->getCheckTime(/** @scrutinizer ignore-type */ $timeStart)));
Loading history...
56
57
        $this->newline();
58
    }
59
60
    protected function getCheckTime(float $timeStart): string
61
    {
62
        return number_format((microtime(true) - $timeStart) * 1000, 2);
63
    }
64
65
    protected function timeTotal(): string
66
    {
67
        return sprintf("<fg=gray>Ran %s checks in {$this->getExecutionTimeString()}</>",
68
            sizeof(ValidationService::checks())
69
        );
70
    }
71
}
72