Completed
Pull Request — master (#59)
by Alessandro
06:35
created

CoverageCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Paraunit\Command;
4
5
use Paraunit\Configuration\ParallelCoverageConfiguration;
6
use Paraunit\Configuration\PhpCodeCoverageCompat;
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
    /**
18
     * ParallelCommand constructor.
19
     * @param ParallelCoverageConfiguration $configuration
20
     */
21 3
    public function __construct(ParallelCoverageConfiguration $configuration)
22
    {
23 3
        parent::__construct($configuration);
24 3
    }
25
26 3
    protected function configure()
27
    {
28 3
        parent::configure();
29
30 3
        $this
31 3
            ->setName('coverage')
32 3
            ->addOption('clover', null, InputOption::VALUE_REQUIRED, 'Output file for Clover XML coverage result')
33 3
            ->addOption('xml', null, InputOption::VALUE_REQUIRED, 'Output dir for PHPUnit XML coverage result')
34 3
            ->addOption('html', null, InputOption::VALUE_REQUIRED, 'Output dir for HTML coverage result');
35 3
    }
36
37
    /**
38
     * @param InputInterface $input
39
     * @param OutputInterface $output
40
     *
41
     * @return int|null
42
     *
43
     * @throws \Exception
44
     */
45 2
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47 2
        if (! $this->hasChosenCoverageMethod($input)) {
48 1
            throw new \InvalidArgumentException('You should choose at least one method of coverage output, between Clover, XML or HTML');
49
        }
50
51 1
        PhpCodeCoverageCompat::load();
52
53 1
        return parent::execute($input, $output);
54
    }
55
56
    /**
57
     * @param InputInterface $input
58
     * @return bool
59
     */
60 2
    private function hasChosenCoverageMethod(InputInterface $input)
61
    {
62 2
        return $input->getOption('clover')
63 2
            || $input->getOption('html')
64 2
            || $input->getOption('xml');
65
    }
66
}
67