Caller::getLimit()   A
last analyzed

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
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Accessories;
6
7
use AlecRabbit\Accessories\Caller\CallerData;
8
use AlecRabbit\Accessories\Caller\CallerDataFormatter;
9
use AlecRabbit\Accessories\Caller\Contracts\CallerConstants;
10
use AlecRabbit\Reports\Core\AbstractReportable;
11
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
63
    {
64 10
        return self::$limit;
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
90
    {
91 8
        return $this->data;
92
    }
93
94
    /**
95
     * @param array $data
96
     */
97 3
    public function setData(array $data): void
98
    {
99 3
        $this->assertData($data);
100 3
        $this->data = $data;
101 3
    }
102
103 3
    protected function assertData(array $data): void
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

103
    protected function assertData(/** @scrutinizer ignore-unused */ array $data): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
    {
105
        // TODO check $data
106 3
    }
107
}
108