Completed
Pull Request — master (#94)
by Alessandro
04:33
created

CommandLineWithCoverage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getExecutable() 0 8 2
A getOptions() 0 14 2
A getSpecificOptions() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Process;
5
6
use Paraunit\Configuration\PHPDbgBinFile;
7
use Paraunit\Configuration\PHPUnitBinFile;
8
use Paraunit\Configuration\PHPUnitConfig;
9
use Paraunit\Configuration\TempFilenameFactory;
10
11
/**
12
 * Class CommandLineWithCoverage
13
 * @package Paraunit\Process
14
 */
15
class CommandLineWithCoverage extends CommandLine
16
{
17
    /** @var PHPDbgBinFile */
18
    private $phpDbgBinFile;
19
20
    /** @var TempFilenameFactory */
21
    private $filenameFactory;
22
23
    /**
24
     * TestCliCommand constructor.
25
     * @param PHPUnitBinFile $phpUnitBin
26
     * @param PHPDbgBinFile $dbgBinFile
27
     * @param TempFilenameFactory $filenameFactory
28
     */
29 6
    public function __construct(
30
        PHPUnitBinFile $phpUnitBin,
31
        PHPDbgBinFile $dbgBinFile,
32
        TempFilenameFactory $filenameFactory
33
    ) {
34 6
        parent::__construct($phpUnitBin);
35
36 6
        $this->phpDbgBinFile = $dbgBinFile;
37 6
        $this->filenameFactory = $filenameFactory;
38
    }
39
40
    /**
41
     * @return string[]
42
     * @throws \RuntimeException
43
     */
44 3
    public function getExecutable(): array
45
    {
46 3
        if ($this->phpDbgBinFile->isAvailable()) {
47 2
            return [$this->phpDbgBinFile->getPhpDbgBin()];
48
        }
49
50 1
        return parent::getExecutable();
51
    }
52
53
    /**
54
     * @param PHPUnitConfig $config
55
     * @return array
56
     * @throws \RuntimeException
57
     */
58 3
    public function getOptions(PHPUnitConfig $config): array
59
    {
60 3
        if (! $this->phpDbgBinFile->isAvailable()) {
61 1
            return parent::getOptions($config);
62
        }
63
64 2
        return array_merge(
65
            [
66 2
                '-qrr',
67 2
                $this->phpUnitBin->getPhpUnitBin()
68
            ],
69 2
            parent::getOptions($config)
70
        );
71
    }
72
73 2
    public function getSpecificOptions(string $testFilename): array
74
    {
75 2
        $options = parent::getSpecificOptions($testFilename);
76 2
        $options[] = '--coverage-php=' . $this->filenameFactory->getFilenameForCoverage(md5($testFilename));
77
78 2
        return $options;
79
    }
80
}
81