Passed
Push — master ( e7208d...6b33a9 )
by Alec
02:04
created

CallerData::getLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Accessories\Caller;
4
5
use AlecRabbit\Accessories\Caller;
6
use AlecRabbit\Accessories\Caller\Contracts\CallerConstants;
7
use AlecRabbit\Accessories\Caller\Contracts\CallerDataInterface;
8
9
class CallerData implements CallerDataInterface, CallerConstants
10
{
11
    /** @var string */
12
    protected $function;
13
14
    /** @var int|null */
15
    protected $line;
16
17
    /** @var string|null */
18
    protected $file;
19
20
    /** @var string|null */
21
    protected $class;
22
23
    /** @var object|null */
24
    protected $object;
25
26
    /** @var string|null */
27
    protected $type;
28
29
    /** @var array|null */
30
    protected $args;
31
32 4
    public function __construct(
33
        array $caller
34
    ) {
35
        $this->function = $caller[self::FUNCTION];
36 4
        $this->parse($caller);
37 4
    }
38
39 4
    protected function parse(array $caller): void
40
    {
41 4
        $this->line = $caller[self::LINE] ?? null;
42 4
        $this->file = $caller[self::FILE] ?? null;
43 4
        $this->class = $caller[self::CLS] ?? null;
44 4
        $this->object = $caller[self::OBJECT] ?? null;
45 4
        $this->type = $caller[self::TYPE] ?? null;
46 4
        $this->args = $caller[self::ARGS] ?? null;
47 4
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 4
    public function __toString(): string
53
    {
54 4
        return Caller::getFormatter()->process($this);
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 4
    public function getFunction(): string
61
    {
62 4
        return $this->function;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 4
    public function getLine(): ?int
69
    {
70 4
        return $this->line;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 4
    public function getFile(): ?string
77
    {
78 4
        return $this->file;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 4
    public function getClass(): ?string
85
    {
86 4
        return $this->class;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 3
    public function getObject(): ?object
93
    {
94 3
        return $this->object;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100 3
    public function getType(): ?string
101
    {
102 3
        return $this->type;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 3
    public function getArgs(): ?array
109
    {
110 3
        return $this->args;
111
    }
112
}
113