Passed
Push — master ( 707534...dc95cb )
by Alec
01:50
created

Caller::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Accessories;
6
7
/** @experimental */
8
class Caller
9
{
10
    public static function method(int $depth = 3): string
11
    {
12
        $caller = static::get($depth);
13
        $r = '';
14
        $function = $caller['function'] . '()';
15
        if (isset($caller['class'])) {
16
            $type = $caller['type'] ?? '';
17
            $r .= $caller['class'] . $type . $function;
18
        } else {
19
            $r .= $function;
20
        }
21
        if (isset($caller['object'])) {
22
            $r .= ' (' . \get_class($caller['object']) . ')';
23
        }
24
        return $r;
25
    }
26
27
    public static function get(int $depth = 2): array
28
    {
29
        return
30
            (new \Exception())->getTrace()[$depth];
31
    }
32
}
33