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

ProcessRunner::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
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