Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
ValidateCommand
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
5 / 5
6
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 runCheck
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getCheckTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 timeTotal
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Hyde\Console\Commands;
6
7use Hyde\Framework\Concerns\TracksExecutionTime;
8use Hyde\Framework\Services\ValidationService;
9use LaravelZero\Framework\Commands\Command;
10
11use function number_format;
12use function microtime;
13use function sprintf;
14use function sizeof;
15
16/**
17 * Run a series of tests to validate your setup and help you optimize your site.
18 */
19class ValidateCommand extends Command
20{
21    use TracksExecutionTime;
22
23    /** @var string */
24    protected $signature = 'validate';
25
26    /** @var string */
27    protected $description = 'Test and validate your project to optimize your site';
28
29    /** @var string */
30    protected $help = 'Run a series of tests to validate your setup and help you optimize your site';
31
32    protected ValidationService $service;
33
34    public function __construct()
35    {
36        parent::__construct();
37
38        $this->service = new ValidationService();
39    }
40
41    public function handle(): int
42    {
43        $this->startClock();
44
45        $this->info('Running validation tests!');
46
47        $this->newLine();
48
49        foreach (ValidationService::checks() as $check) {
50            $this->runCheck($check);
51        }
52
53        $this->info("All done! {$this->timeTotal()}");
54
55        return Command::SUCCESS;
56    }
57
58    protected function runCheck(string $check): void
59    {
60        $timeStart = microtime(true);
61        $result = $this->service->run($check);
62
63        $this->line($result->formattedMessage($this->getCheckTime($timeStart)));
64
65        $this->newline();
66    }
67
68    protected function getCheckTime(float $timeStart): string
69    {
70        return number_format((microtime(true) - $timeStart) * 1000, 2);
71    }
72
73    protected function timeTotal(): string
74    {
75        return sprintf("<fg=gray>Ran %s checks in {$this->getExecutionTimeString()}</>",
76            sizeof(ValidationService::checks())
77        );
78    }
79}