Passed
Pull Request — 0.6.x (#223)
by Shinji
01:41
created

CompatCallTraceFormatter::format()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
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\Compat;
15
16
use Reli\Inspector\Output\TraceFormatter\CallTraceFormatter;
17
use Reli\Lib\PhpProcessReader\CallTrace;
18
19
use function join;
20
21
final class CompatCallTraceFormatter implements CallTraceFormatter
22
{
23
    private static ?self $cache;
24
25
    public function __construct(
26
        private CompatCallFrameFormatter $call_frame_formatter,
27
    ) {
28
    }
29
30
    public static function getInstance(): self
31
    {
32
        if (!isset(self::$cache)) {
33
            self::$cache = new self(new CompatCallFrameFormatter());
34
        }
35
        return self::$cache;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::cache could return the type null which is incompatible with the type-hinted return Reli\Inspector\Output\Tr...ompatCallTraceFormatter. Consider adding an additional type-check to rule them out.
Loading history...
36
    }
37
38
    public function format(CallTrace $call_trace): string
39
    {
40
        $frames = [];
41
        foreach ($call_trace->call_frames as $call_frame) {
42
            $frames[] = $this->call_frame_formatter->format($call_frame);
43
        }
44
        return join(PHP_EOL, $frames);
45
    }
46
}
47