Completed
Push — master ( 2da503...38628d )
by Shinji
14s queued 11s
created

CompatCallTraceFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler 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 PhpProfiler\Inspector\Output\TraceFormatter\Compat;
15
16
use PhpProfiler\Inspector\Output\TraceFormatter\CallTraceFormatter;
17
use PhpProfiler\Lib\PhpProcessReader\CallTrace;
18
19
final class CompatCallTraceFormatter implements CallTraceFormatter
20
{
21
    private CompatCallFrameFormatter $call_frame_formatter;
22
    private static ?self $cache;
23
24
    public static function getInstance(): self
25
    {
26
        if (!isset(self::$cache)) {
27
            self::$cache = new self(new CompatCallFrameFormatter());
28
        }
29
        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 PhpProfiler\Inspector\Ou...ompatCallTraceFormatter. Consider adding an additional type-check to rule them out.
Loading history...
30
    }
31
32
    public function __construct(
33
        CompatCallFrameFormatter $call_frame_formatter
34
    ) {
35
        $this->call_frame_formatter = $call_frame_formatter;
36
    }
37
38
39
40
    public function format(CallTrace $call_trace): string
41
    {
42
        $frames = [];
43
        foreach ($call_trace->call_frames as $call_frame) {
44
            $frames[] = $this->call_frame_formatter->format($call_frame);
45
        }
46
        return join(PHP_EOL, $frames);
47
    }
48
}
49