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

Caller   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 23
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A method() 0 15 3
A get() 0 4 1
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