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

CommandLine   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 56
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getExecutable() 0 4 1
A getOptions() 0 13 2
A buildPhpunitOptionString() 0 9 2
A getSpecificOptions() 0 4 1
1
<?php
2
3
namespace Paraunit\Process;
4
5
use Paraunit\Configuration\PHPUnitBinFile;
6
use Paraunit\Configuration\PHPUnitConfig;
7
use Paraunit\Configuration\PHPUnitOption;
8
use Paraunit\Parser\JSON\LogPrinter;
9
10
/**
11
 * Class TestCliCommand
12
 * @package Paraunit\Process
13
 */
14
class CommandLine
15
{
16
    /** @var  PHPUnitBinFile */
17
    protected $phpUnitBin;
18
19
    /**
20
     * TestCliCommand constructor.
21
     * @param PHPUnitBinFile $phpUnitBin
22
     */
23 36
    public function __construct(PHPUnitBinFile $phpUnitBin)
24
    {
25 36
        $this->phpUnitBin = $phpUnitBin;
26
    }
27
28
    /**
29
     * @return string[]
30
     */
31 30
    public function getExecutable(): array
32
    {
33 30
        return ['php', $this->phpUnitBin->getPhpUnitBin()];
34
    }
35
36
    /**
37
     * @param PHPUnitConfig $config
38
     * @return array
39
     * @throws \RuntimeException When the config handling fails
40
     */
41 32
    public function getOptions(PHPUnitConfig $config): array
42
    {
43
        $options = [
44 32
            '--configuration=' . $config->getFileFullPath(),
45
            '--printer=' . LogPrinter::class,
46
        ];
47
48 32
        foreach ($config->getPhpunitOptions() as $phpunitOption) {
49 6
            $options[] = $this->buildPhpunitOptionString($phpunitOption);
50
        }
51
52 32
        return $options;
53
    }
54
55 6
    private function buildPhpunitOptionString(PHPUnitOption $option): string
56
    {
57 6
        $optionString = '--' . $option->getName();
58 6
        if ($option->hasValue()) {
59 5
            $optionString .= '=' . $option->getValue();
60
        }
61
62 6
        return $optionString;
63
    }
64
65 16
    public function getSpecificOptions(string $testFilename): array
66
    {
67 16
        return [];
68
    }
69
}
70