ProcessFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 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 implements ProcessFactoryInterface
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 41
    public function __construct(
34
        CommandLine $cliCommand,
35
        PHPUnitConfig $phpunitConfig,
36
        TempFilenameFactory $tempFilenameFactory
37
    ) {
38 41
        $this->cliCommand = $cliCommand;
39 41
        $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 41
        $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 41
            EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
42
        ];
43
    }
44
45 25
    public function create(string $testFilePath): AbstractParaunitProcess
46
    {
47 25
        $process = new Process(
48 25
            array_merge($this->baseCommandLine, [$testFilePath], $this->cliCommand->getSpecificOptions($testFilePath)),
49 25
            null,
50 25
            $this->environmentVariables
51
        );
52
53 25
        if (method_exists($process, 'inheritEnvironmentVariables')) {
54
            // method added in 3.0
55 25
            $process->inheritEnvironmentVariables();
56
        }
57
58 25
        return new SymfonyProcessWrapper($process, $testFilePath);
59
    }
60
}
61