RunCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 16 2
1
<?php
2
3
namespace Leankoala\HealthFoundation\Cli\Command;
4
5
use Leankoala\HealthFoundation\Config\FormatFactory;
6
use Leankoala\HealthFoundation\Config\HealthFoundationFactory;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Yaml\Yaml;
12
13
14
class RunCommand extends Command
15
{
16
    protected function configure()
17
    {
18
        $this
19
            ->setDefinition([
20
                new InputArgument('config', InputArgument::REQUIRED, 'the configuration file')
21
            ])
22
            ->setDescription('Run health checks.')
23
            ->setHelp('The <info>run</info> command for the health checker.')
24
            ->setName('run');
25
    }
26
27
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        $configFile = (string)$input->getArgument('config');
30
31
        if (!file_exists($configFile)) {
32
            throw new \RuntimeException('Unable to find config file.');
33
        }
34
35
        $configArray = Yaml::parse(file_get_contents($configFile));
36
37
        $healthFoundation = HealthFoundationFactory::from($configArray);
38
        $format = FormatFactory::from($configArray);
39
40
        $runResult = $healthFoundation->runHealthCheck();
41
42
        $format->handle($runResult);
43
    }
44
}
45