Passed
Pull Request — master (#32)
by Shinji
02:22
created

CallFrameFormatter::formatOpLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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