ProcessFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2020 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Common\Process;
13
14
use Symfony\Component\Process\Process;
15
16
final class ProcessFactory
17
{
18
    /** @var array */
19
    private $command;
20
21
    /** @var null|ProcessParamsInterface */
22
    private $processParams;
23
24
    /**
25
     * @param array                       $command
26
     * @param null|ProcessParamsInterface $processParams
27
     */
28 38
    public function __construct(array $command, ?ProcessParamsInterface $processParams = null)
29
    {
30 38
        $this->command       = $command;
31 38
        $this->processParams = $processParams;
32 38
    }
33
34 38
    public function __invoke(): Process
35
    {
36 38
        $process = new Process($this->command);
37 38
        if ($this->processParams !== null) {
38 38
            $process->setTimeout($this->processParams->getTimeout());
39 38
            $process->setIdleTimeout($this->processParams->getIdleTimeout());
40 38
            $process->setEnv($this->processParams->getEnv());
41
        }
42
43 38
        return $process;
44
    }
45
}
46