Total Complexity | 10 |
Total Lines | 93 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 4 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class Caller extends AbstractReportable implements CallerConstants |
||
13 | { |
||
14 | /** @var int */ |
||
15 | protected static $limit = 0; |
||
16 | |||
17 | /** @var int */ |
||
18 | protected static $options = DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS; |
||
19 | |||
20 | /** @var array */ |
||
21 | protected $data; |
||
22 | |||
23 | 9 | public function __construct(int $depth = null) |
|
24 | { |
||
25 | 9 | parent::__construct(); |
|
26 | 9 | $this->data = $this->getCallerData($depth ?? 2); |
|
27 | 9 | $this->setBindings( |
|
28 | 9 | CallerData::class, |
|
29 | 9 | CallerDataFormatter::class |
|
30 | ); |
||
31 | 9 | } |
|
32 | |||
33 | /** |
||
34 | * @param int $depth |
||
35 | * @return array |
||
36 | */ |
||
37 | 9 | protected function getCallerData(int $depth): array |
|
38 | { |
||
39 | return |
||
40 | 9 | debug_backtrace(static::getOptions(), static::getLimit())[++$depth] ?? self::UNDEFINED; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return int |
||
45 | */ |
||
46 | 10 | public static function getOptions(): int |
|
47 | { |
||
48 | 10 | return self::$options; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param int $options |
||
53 | */ |
||
54 | 1 | public static function setOptions(int $options): void |
|
55 | { |
||
56 | 1 | self::$options = $options; |
|
57 | 1 | } |
|
58 | |||
59 | /** |
||
60 | * @return int |
||
61 | */ |
||
62 | 10 | public static function getLimit(): int |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * @param int $limit |
||
69 | */ |
||
70 | 1 | public static function setLimit(int $limit): void |
|
71 | { |
||
72 | 1 | self::$limit = $limit; |
|
73 | 1 | } |
|
74 | |||
75 | /** |
||
76 | * @param null|int $depth |
||
77 | * @return CallerData |
||
78 | */ |
||
79 | 4 | public static function get(?int $depth = null): CallerData |
|
80 | { |
||
81 | /** @var CallerData $report */ |
||
82 | 4 | $report = (new static($depth ?? 3))->report(); |
|
83 | 4 | return $report; |
|
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return array |
||
88 | */ |
||
89 | 8 | public function getData(): array |
|
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param array $data |
||
96 | */ |
||
97 | 3 | public function setData(array $data): void |
|
101 | 3 | } |
|
102 | |||
103 | 3 | protected function assertData(array $data): void |
|
105 | // TODO check $data |
||
106 | 3 | } |
|
107 | } |
||
108 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.