CompatCallFrameFormatter::formatOpLine()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 6
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\Lib\PhpProcessReader\CallFrame;
17
18
use function is_null;
19
20
final class CompatCallFrameFormatter
21
{
22
    public function format(CallFrame $call_frame): string
23
    {
24
        return "{$this->formatFunctionName($call_frame)} {$call_frame->file_name}({$this->formatOpLine($call_frame)})";
25
    }
26
27
    private function formatFunctionName(CallFrame $call_frame): string
28
    {
29
        if ($call_frame->class_name === '') {
30
            return $call_frame->function_name;
31
        }
32
        return "{$call_frame->class_name}::{$call_frame->function_name}";
33
    }
34
35
    private function formatOpLine(CallFrame $call_frame): string
36
    {
37
        if (is_null($call_frame->opline)) {
38
            return '-1';
39
        }
40
        return "{$call_frame->opline->lineno}";
41
    }
42
}
43