Failed Conditions
Push — master ( 01d6ae...9ca6d9 )
by Philippe
534:14 queued 469:10
created

ProcessRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 23
rs 10
c 0
b 0
f 0
ccs 6
cts 9
cp 0.6667
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpSpellcheck\Utils;
6
7
use PhpSpellcheck\Exception\ProcessFailedException;
8
use Symfony\Component\Process\Exception\ExceptionInterface;
9
use Symfony\Component\Process\Process;
10
11
class ProcessRunner
12
{
13 14
    /**
14
     * @param int|float|null $timeout The timeout in seconds
15 14
     */
16
    public static function run(Process $process, $timeout = null, callable $callback = null, array $env = []): Process
17 14
    {
18
        if (method_exists($process, 'inheritEnvironmentVariables')) {
19
            // Symfony 3.2+
20
            $process->inheritEnvironmentVariables(true);
21
        } else {
22 14
            // Symfony < 3.2
23
            $process->setEnv(['LANG' => getenv('LANG')]);
24
        }
25 14
        $process->setTimeout($timeout);
26
27
        try {
28
            $process->mustRun($callback, $env);
29
        } catch (ExceptionInterface $e) {
30 14
            throw new ProcessFailedException($process, $e);
31
        }
32
33
        return $process;
34
    }
35
}
36