Test Failed
Push — master ( 57b7d4...e042c7 )
by Hannes
02:15
created

ProcessRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 14 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester\Runner;
6
7
use hanneskod\readmetester\Parser\CodeBlock;
8
use Symfony\Component\Process\PhpProcess;
9
10
/**
11
 * Execute code in isolation using symfony php-process
12
 */
13
class ProcessRunner implements RunnerInterface
14
{
15
    public function run(CodeBlock $codeBlock): OutcomeInterface
16
    {
17
        $process = new PhpProcess("<?php $codeBlock");
18
        $process->run();
19
20
        if ($errorOutput = $process->getErrorOutput()) {
21
            return new ErrorOutcome(trim($errorOutput));
22
        }
23
24
        if ($output = $process->getOutput()) {
25
            return new OutputOutcome($output);
26
        }
27
28
        return new VoidOutcome;
29
    }
30
}
31