Passed
Push — 0.6.x ( 9a1948...a98caa )
by Shinji
03:23 queued 01:32
created

TemplatedCallTraceFormatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Reli\Inspector\Output\TraceFormatter\Templated;
15
16
use Reli\Inspector\Output\TraceFormatter\CallTraceFormatter;
17
use Reli\Lib\PhpProcessReader\CallTrace;
18
19
use function assert;
20
use function is_string;
21
use function ob_get_clean;
22
use function ob_start;
23
24
final class TemplatedCallTraceFormatter implements CallTraceFormatter
25
{
26
    public function __construct(
27
        private TemplatePathResolverInterface $template_path_resolver,
28
        private string $template
29
    ) {
30
    }
31
32
    public function format(CallTrace $call_trace): string
33
    {
34
        ob_start();
35
        /** @psalm-suppress UnresolvableInclude */
36
        include $this->template_path_resolver->resolve($this->template);
37
        $buffer = ob_get_clean();
38
        assert(is_string($buffer));
39
        return $buffer;
40
    }
41
}
42