Completed
Pull Request — master (#112)
by Alessandro
10:33 queued 35s
created

ProcessFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A create() 0 11 1
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\Process;
11
12
/**
13
 * Class ProcessFactory
14
 * @package Paraunit\Process
15
 */
16
class ProcessFactory
17
{
18
    /** @var CommandLine */
19
    private $cliCommand;
20
21
    /** @var string[] */
22
    private $baseCommandLine;
23
24
    /** @var string[] */
25
    private $environmentVariables;
26
27
    /**
28
     * ProcessFactory constructor.
29
     * @param CommandLine $cliCommand
30
     * @param PHPUnitConfig $phpunitConfig
31
     * @param TempFilenameFactory $tempFilenameFactory
32
     */
33
    public function __construct(
34
        CommandLine $cliCommand,
35
        PHPUnitConfig $phpunitConfig,
36
        TempFilenameFactory $tempFilenameFactory
37
    ) {
38
        $this->cliCommand = $cliCommand;
39
        $this->baseCommandLine = array_merge($this->cliCommand->getExecutable(), $this->cliCommand->getOptions($phpunitConfig));
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->cliCo...ptions($phpunitConfig)) of type array is incompatible with the declared type array<integer,string> of property $baseCommandLine.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        $this->environmentVariables = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array(\Paraunit\Configur...ctory->getPathForLog()) of type array<string|integer,string> is incompatible with the declared type array<integer,string> of property $environmentVariables.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
            EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
42
        ];
43
    }
44
45
    public function create(string $testFilePath): AbstractParaunitProcess
46
    {
47
        $process = new Process(
48
            array_merge($this->baseCommandLine, [$testFilePath], $this->cliCommand->getSpecificOptions($testFilePath)),
49
            null,
50
            $this->environmentVariables
51
        );
52
        $process->inheritEnvironmentVariables();
53
54
        return new SymfonyProcessWrapper($process, $testFilePath);
55
    }
56
}
57