ProcessRunner   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 7
c 3
b 0
f 0
dl 0
loc 17
ccs 5
cts 8
cp 0.625
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 11 2
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 float|int|null $timeout The timeout in seconds
15 14
     * @param array<string, string> $env
16
     */
17 14
    public static function run(Process $process, $timeout = null, callable $callback = null, array $env = []): Process
18
    {
19
        $process->setTimeout($timeout);
20
21
        try {
22 14
            $process->mustRun($callback, $env);
23
        } catch (ExceptionInterface $e) {
24
            throw new ProcessFailedException($process, $e);
25 14
        }
26
27
        return $process;
28
    }
29
}
30