Completed
Push — master ( 462b02...eea460 )
by Alessandro
04:21
created

CoverageCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 66
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 14 1
A execute() 0 10 2
A hasChosenCoverageMethod() 0 10 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Command;
5
6
use Paraunit\Configuration\CoverageConfiguration;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class CoverageCommand
13
 * @package Paraunit\Command
14
 */
15
class CoverageCommand extends ParallelCommand
16
{
17
    const COVERAGE_METHODS = [
18
        'clover',
19
        'html',
20
        'xml',
21
        'text',
22
        'text-to-console',
23
        'crap4j',
24
        'php',
25
    ];
26
27
    /**
28
     * ParallelCommand constructor.
29
     * @param CoverageConfiguration $configuration
30
     */
31 9
    public function __construct(CoverageConfiguration $configuration)
32
    {
33 9
        parent::__construct($configuration);
34
    }
35
36 9
    protected function configure()
37
    {
38 9
        parent::configure();
39
40 9
        $this->setName('coverage');
41 9
        $this->setDescription('Fetch the coverage of your tests in parallel');
42 9
        $this->addOption('clover', null, InputOption::VALUE_REQUIRED, 'Output file for Clover XML coverage result');
43 9
        $this->addOption('xml', null, InputOption::VALUE_REQUIRED, 'Output dir for PHPUnit XML coverage result');
44 9
        $this->addOption('html', null, InputOption::VALUE_REQUIRED, 'Output dir for HTML coverage result');
45 9
        $this->addOption('text', null, InputOption::VALUE_REQUIRED, 'Output file for text coverage result');
46 9
        $this->addOption('text-to-console', null, InputOption::VALUE_NONE, 'Output text coverage directly to console');
47 9
        $this->addOption('crap4j', null, InputOption::VALUE_REQUIRED, 'Output file for Crap4j coverage result');
48 9
        $this->addOption('php', null, InputOption::VALUE_REQUIRED, 'Output file for PHP coverage result');
49
    }
50
51
    /**
52
     * @param InputInterface $input
53
     * @param OutputInterface $output
54
     *
55
     * @return int|null
56
     *
57
     * @throws \Exception
58
     */
59 8
    protected function execute(InputInterface $input, OutputInterface $output)
60
    {
61 8
        if (! $this->hasChosenCoverageMethod($input)) {
62 1
            $coverageMethods = implode(self::COVERAGE_METHODS, ', ');
63
64 1
            throw new \InvalidArgumentException('You should choose at least one method of coverage output between ' . $coverageMethods);
65
        }
66
67 7
        return parent::execute($input, $output);
68
    }
69
70 8
    private function hasChosenCoverageMethod(InputInterface $input): bool
71
    {
72 8
        foreach (self::COVERAGE_METHODS as $coverageMethod) {
73 8
            if ($input->getOption($coverageMethod)) {
74 8
                return true;
75
            }
76
        }
77
78 1
        return false;
79
    }
80
}
81