CompileObjectGraph::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 9
c 5
b 0
f 0
dl 0
loc 15
rs 9.9666
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Package\Compiler;
6
7
use Ray\Di\AbstractModule;
8
use Ray\ObjectGrapher\ObjectGrapher;
9
10
use function passthru;
11
use function sprintf;
12
use function str_replace;
13
14
final class CompileObjectGraph
15
{
16
    public function __construct(
17
        private FilePutContents $filePutContents,
18
        private string $dotDir,
19
    ) {
20
    }
21
22
    public function __invoke(AbstractModule $module): string
23
    {
24
        $dotFile = sprintf('%s/module.dot', $this->dotDir);
25
        ($this->filePutContents)($dotFile, (new ObjectGrapher())($module));
26
        $svgFile = str_replace('.dot', '.svg', $dotFile);
27
        $cmd = "dot -Tsvg {$dotFile} -o {$svgFile}";
28
        passthru('which dotsrc/Compiler/FakeRun.php 2>/dev/null', $status);
29
        // @codeCoverageIgnoreStart
30
        if ($status === 0) {
31
            passthru($cmd, $status);
32
33
            return $svgFile;
34
        }
35
36
        return $dotFile;
37
        // @codeCoverageIgnoreEnd
38
    }
39
}
40