1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Accessories\Caller; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Accessories\Caller; |
6
|
|
|
use AlecRabbit\Accessories\Caller\Contracts\CallerDataInterface; |
7
|
|
|
use AlecRabbit\Reports\Contracts\ReportableInterface; |
8
|
|
|
use AlecRabbit\Reports\Contracts\ReportInterface; |
9
|
|
|
use AlecRabbit\Reports\Core\AbstractReport; |
10
|
|
|
|
11
|
|
|
class CallerData extends AbstractReport implements CallerDataInterface |
12
|
|
|
{ |
13
|
|
|
/** @var string */ |
14
|
|
|
protected $function; |
15
|
|
|
|
16
|
|
|
/** @var int|null */ |
17
|
|
|
protected $line; |
18
|
|
|
|
19
|
|
|
/** @var string|null */ |
20
|
|
|
protected $file; |
21
|
|
|
|
22
|
|
|
/** @var string|null */ |
23
|
|
|
protected $class; |
24
|
|
|
|
25
|
|
|
/** @var object|null */ |
26
|
|
|
protected $object; |
27
|
|
|
|
28
|
|
|
/** @var string|null */ |
29
|
|
|
protected $type; |
30
|
|
|
|
31
|
|
|
/** @var array|null */ |
32
|
|
|
protected $args; |
33
|
|
|
|
34
|
8 |
|
public function __construct( |
35
|
|
|
array $caller = null |
36
|
|
|
) { |
37
|
8 |
|
$caller = $caller ?? self::UNDEFINED; |
38
|
|
|
$this->function = $caller[self::FUNCTION]; |
39
|
8 |
|
$this->parse($caller); |
40
|
8 |
|
} |
41
|
|
|
|
42
|
8 |
|
protected function parse(array $caller): void |
43
|
|
|
{ |
44
|
8 |
|
$this->line = $caller[self::LINE] ?? null; |
45
|
8 |
|
$this->file = $caller[self::FILE] ?? null; |
46
|
8 |
|
$this->class = $caller[self::CLS] ?? null; |
47
|
8 |
|
$this->object = $caller[self::OBJECT] ?? null; |
48
|
8 |
|
$this->type = $caller[self::TYPE] ?? null; |
49
|
8 |
|
$this->args = $caller[self::ARGS] ?? null; |
50
|
8 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
4 |
|
public function __toString(): string |
56
|
|
|
{ |
57
|
4 |
|
return Caller::getFormatter()->format($this); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
6 |
|
public function getFunction(): string |
64
|
|
|
{ |
65
|
6 |
|
return $this->function; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
4 |
|
public function getLine(): ?int |
72
|
|
|
{ |
73
|
4 |
|
return $this->line; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
4 |
|
public function getFile(): ?string |
80
|
|
|
{ |
81
|
4 |
|
return $this->file; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
6 |
|
public function getClass(): ?string |
88
|
|
|
{ |
89
|
6 |
|
return $this->class; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
3 |
|
public function getObject(): ?object |
96
|
|
|
{ |
97
|
3 |
|
return $this->object; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
4 |
|
public function getType(): ?string |
104
|
|
|
{ |
105
|
4 |
|
return $this->type; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
3 |
|
public function getArgs(): ?array |
112
|
|
|
{ |
113
|
3 |
|
return $this->args; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param ReportableInterface $reportable |
118
|
|
|
* @return ReportInterface |
119
|
|
|
*/ |
120
|
2 |
|
public function buildOn(ReportableInterface $reportable): ReportInterface |
121
|
|
|
{ |
122
|
2 |
|
if ($reportable instanceof Caller) { |
123
|
1 |
|
return $this; |
124
|
|
|
} |
125
|
1 |
|
throw new \InvalidArgumentException( |
126
|
1 |
|
Caller::class . ' expected, ' . get_class($reportable) . ' given.' |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|