Passed
Push — master ( 6b33a9...df14c7 )
by Alec
01:59
created

CallerDataFormatter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 47
ccs 22
cts 24
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 17 2
A getLineAndFile() 0 11 2
A getFunction() 0 8 2
1
<?php declare(strict_types=1);
2
3
4
namespace AlecRabbit\Accessories\Caller;
5
6
use AlecRabbit\Accessories\Caller\Contracts\CallerConstants;
7
use AlecRabbit\Accessories\Caller\Contracts\CallerDataFormatterInterface;
8
9
class CallerDataFormatter implements CallerDataFormatterInterface, CallerConstants
10
{
11 4
    public function process(CallerData $data): string
12
    {
13 4
        if (null !== $class = $data->getClass()) {
14
            return
15 3
                sprintf(
16 3
                    '%s%s%s%s',
17 3
                    $class,
18 3
                    $data->getType(),
19 3
                    $this->getFunction($data),
20 3
                    $this->getLineAndFile($data)
21
                );
22
        }
23
        return
24 1
            sprintf(
25 1
                '%s%s',
26 1
                $this->getFunction($data),
27 1
                $this->getLineAndFile($data)
28
            );
29
    }
30
31 4
    private function getFunction(CallerData $caller)
32
    {
33 4
        if (self::STR_UNDEFINED === $function = $caller->getFunction()) {
34
            $function = ucfirst($function);
35
        } else {
36 4
            $function .= '()';
37
        }
38 4
        return $function;
39
    }
40
41
    /**
42
     * @param CallerData $caller
43
     * @return string
44
     */
45 4
    private function getLineAndFile(CallerData $caller): string
46
    {
47 4
        if (self::STR_UNDEFINED !== $caller->getFunction()) {
48
            return
49 4
                sprintf(
50 4
                    ' [%s:"%s"]',
51 4
                    $caller->getLine(),
52 4
                    $caller->getFile()
53
                );
54
        }
55
        return '';
56
    }
57
}
58