ProcessBuilderFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 45
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 3
A create() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Process;
6
7
use Paraunit\Configuration\EnvVariables;
8
use Paraunit\Configuration\PHPUnitConfig;
9
use Paraunit\Configuration\TempFilenameFactory;
10
use Symfony\Component\Process\ProcessBuilder;
11
12
/**
13
 * Class ProcessBuilderFactory
14
 * @package Paraunit\Process
15
 */
16
class ProcessBuilderFactory implements ProcessFactoryInterface
17
{
18
    /** @var ProcessBuilder */
19
    private $builderPrototype;
20
    /** @var CommandLine */
21
    private $cliCommand;
22
23
    /**
24
     * ProcessBuilderFactory constructor.
25
     * @param CommandLine $cliCommand
26
     * @param PHPUnitConfig $phpunitConfig
27
     * @param TempFilenameFactory $tempFilenameFactory
28
     */
29
    public function __construct(
30
        CommandLine $cliCommand,
31
        PHPUnitConfig $phpunitConfig,
32
        TempFilenameFactory $tempFilenameFactory
33
    ) {
34
        $this->cliCommand = $cliCommand;
35
        $this->builderPrototype = new ProcessBuilder();
36
37
        $this->builderPrototype->addEnvironmentVariables([
38
            EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
39
        ]);
40
41
        foreach ($this->cliCommand->getExecutable() as $item) {
42
            $this->builderPrototype->add($item);
43
        }
44
45
        foreach ($this->cliCommand->getOptions($phpunitConfig) as $option) {
46
            $this->builderPrototype->add($option);
47
        }
48
    }
49
50
    public function create(string $testFilePath): AbstractParaunitProcess
51
    {
52
        $builder = clone $this->builderPrototype;
53
        $builder->add($testFilePath);
54
        foreach ($this->cliCommand->getSpecificOptions($testFilePath) as $specificOption) {
55
            $builder->add($specificOption);
56
        }
57
58
        return new SymfonyProcessWrapper($builder->getProcess(), $testFilePath);
59
    }
60
}
61