Passed
Push — main ( d47b18...48e99f )
by Chema
14:19 queued 08:08
created

DoctorCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phel\Run\Infrastructure\Command;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
use function extension_loaded;
12
use function sprintf;
13
14
final class DoctorCommand extends Command
15
{
16 1
    protected function configure(): void
17
    {
18 1
        $this->setName('doctor')
19 1
            ->setDescription('Check system requirements for running the Phel CLI');
20
    }
21
22 1
    protected function execute(InputInterface $input, OutputInterface $output): int
23
    {
24 1
        $output->writeln('Checking requirements:');
25
26 1
        $requirements = [
27 1
            ['label' => 'PHP >= 8.2', 'status' => PHP_VERSION_ID >= 80200],
28 1
            ['label' => 'json extension', 'status' => extension_loaded('json')],
29 1
            ['label' => 'mbstring extension', 'status' => extension_loaded('mbstring')],
30 1
            ['label' => 'readline extension', 'status' => extension_loaded('readline')],
31 1
        ];
32
33 1
        $success = true;
34 1
        foreach ($requirements as $req) {
35 1
            $ok = $req['status'];
36 1
            $success = $success && $ok;
37 1
            $output->writeln(sprintf(' - %s: %s', $req['label'], $ok ? '<info>OK</info>' : '<error>FAIL</error>'));
38
        }
39
40 1
        if ($success) {
41 1
            $output->writeln('<info>Your system meets all requirements.</info>');
42
43 1
            return Command::SUCCESS;
44
        }
45
46
        $output->writeln('<error>Your system does not meet all requirements.</error>');
47
48
        return Command::FAILURE;
49
    }
50
}
51