CompileObjectGraph   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
dl 0
loc 23
rs 10
c 5
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
A __construct() 0 4 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