ProcessRunner::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 2
b 0
f 0
nc 2
nop 4
dl 0
loc 11
ccs 3
cts 6
cp 0.5
crap 2.5
rs 10
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