ProcessFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 2
b 0
f 0
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 10 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