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

EvalRunner   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 22 4
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester\Runner;
6
7
use hanneskod\readmetester\Parser\CodeBlock;
8
9
/**
10
 * Execute code using eval()
11
 */
12
class EvalRunner implements RunnerInterface
13
{
14
    public function run(CodeBlock $codeBlock): OutcomeInterface
15
    {
16
        ob_start();
17
18
        try {
19
            $lastErrorBefore = error_get_last();
20
            @eval($codeBlock);
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
21
            $lastErrorAfter = error_get_last();
22
            if ($lastErrorBefore != $lastErrorAfter) {
23
                ob_end_clean();
24
                return new ErrorOutcome("{$lastErrorAfter['type']}: {$lastErrorAfter['message']}");
25
            }
26
        } catch (\Throwable $e) {
27
            ob_end_clean();
28
            return new ErrorOutcome((string)$e);
29
        }
30
31
        if ($output = ob_get_clean()) {
32
            return new OutputOutcome($output);
33
        }
34
35
        return new VoidOutcome;
36
    }
37
}
38