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

CoverageCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 56
ccs 24
cts 24
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 12 1
A execute() 0 10 2
B hasChosenCoverageMethod() 0 8 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