ProcessRunner::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Runner;
6
7
use hanneskod\readmetester\Example\ExampleObj;
0 ignored issues
show
Bug introduced by
The type hanneskod\readmetester\Example\ExampleObj was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use hanneskod\readmetester\Example\ExampleStoreInterface;
9
use Symfony\Component\Process\PhpProcess;
10
11
/**
12
 * Execute code in isolation using symfony php-process
13
 */
14
final class ProcessRunner implements RunnerInterface
15
{
16
    private string $bootstrap = '';
17
18
    public function setBootstrap(string $filename): void
19
    {
20
        if ($filename) {
21
            $this->bootstrap = "require_once '$filename';";
22
        }
23
    }
24
25
    public function run(ExampleStoreInterface $examples): iterable
26
    {
27
        foreach ($examples->getExamples() as $example) {
28
            yield $this->runExample($example);
29
        }
30
    }
31
32
    public function runExample(ExampleObj $example): OutcomeInterface
33
    {
34
        $filename = (string)tempnam(sys_get_temp_dir(), 'readmetester');
35
36
        file_put_contents($filename, "<?php {$example->getCodeBlock()->getCode()}");
37
38
        $process = new PhpProcess("<?php {$this->bootstrap} require '$filename';");
39
        $process->run();
40
41
        unlink($filename);
42
43
        if ($errorOutput = $process->getErrorOutput()) {
44
            return new ErrorOutcome($example, trim($errorOutput));
0 ignored issues
show
Bug introduced by
The type hanneskod\readmetester\Runner\ErrorOutcome was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
        }
46
47
        if ($output = $process->getOutput()) {
48
            return new OutputOutcome($example, $output);
0 ignored issues
show
Bug introduced by
The type hanneskod\readmetester\Runner\OutputOutcome was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
        }
50
51
        return new VoidOutcome($example);
0 ignored issues
show
Bug introduced by
The type hanneskod\readmetester\Runner\VoidOutcome was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
    }
53
}
54