Completed
Pull Request — master (#79)
by Alessandro
05:47
created

CoverageCommand::hasChosenCoverageMethod()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

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