Passed
Push — develop ( d2ca78...d47000 )
by Alec
03:19
created

BenchmarkFunction::getFunction()   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
2
/**
3
 * User: alec
4
 * Date: 03.12.18
5
 * Time: 22:24
6
 */
7
8
namespace AlecRabbit\Tools\Internal;
9
10
use AlecRabbit\Tools\Timer;
11
use AlecRabbit\Traits\GettableName;
12
use function AlecRabbit\brackets;
13
use function AlecRabbit\str_decorate;
14
use const AlecRabbit\Constants\BRACKETS_ANGLE;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Constants\BRACKETS_ANGLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
15
16
/**
17
 * Class BenchmarkFunction
18
 * @package AlecRabbit
19
 * @internal
20
 */
21
class BenchmarkFunction
22
{
23
    use GettableName;
24
25
    /** @var null|string */
26
    private $comment;
27
28
    /** @var int */
29
    private $index;
30
31
    /** @var array */
32
    private $args;
33
34
    /** @var callable */
35
    private $func;
36
37
    /** @var mixed */
38
    private $result;
39
40
    /** @var Timer */
41
    private $timer;
42
43
    /** @var \Throwable|null */
44
    private $exception;
45
46
    /**
47
     * BenchmarkFunction constructor.
48
     * @param callable $func
49
     * @param string $name
50
     * @param int $index
51
     * @param array $args
52
     * @param null|string $comment
53
     */
54 2
    public function __construct($func, string $name, int $index, array $args, ?string $comment = null)
55
    {
56 2
        $this->func = $func;
57 2
        $this->comment = $comment;
58 2
        $this->name = $name;
59 2
        $this->index = $index;
60 2
        $this->args = $args;
61 2
    }
62
63
    /**
64
     * @return string
65
     */
66 2
    public function getComment(): string
67
    {
68 2
        return $this->comment ? str_decorate($this->comment, '"') : '';
69
    }
70
71
    /**
72
     * @return array
73
     */
74 2
    public function getArgs(): array
75
    {
76 2
        return $this->args;
77
    }
78
79
    /**
80
     * @return callable
81
     */
82 2
    public function getFunction(): callable
83
    {
84 2
        return $this->func;
85
    }
86
87 2
    public function getEnumeratedName(): string
88
    {
89
        return
90 2
            brackets((string)$this->index, BRACKETS_ANGLE) . ' ' . $this->name;
91
    }
92
93
    /**
94
     * @return mixed
95
     */
96 1
    public function getResult()
97
    {
98 1
        return $this->result;
99
    }
100
101
    /**
102
     * @param mixed $result
103
     */
104 2
    public function setResult($result): void
105
    {
106 2
        $this->result = $result;
107 2
    }
108
109
    /**
110
     * @return string
111
     */
112 2
    public function getIndexedName(): string
113
    {
114 2
        return sprintf(
115 2
            '⟨%s⟩ %s',
116 2
            $this->getIndex(),
117 2
            $this->getName()
118
        );
119
    }
120
121
    /**
122
     * @return int
123
     */
124 2
    public function getIndex(): int
125
    {
126 2
        return $this->index;
127
    }
128
129
    /**
130
     * @return Timer
131
     */
132
    public function getTimer(): Timer
133
    {
134
        return $this->timer;
135
    }
136
137
    /**
138
     * @param Timer $timer
139
     * @return BenchmarkFunction
140
     */
141 2
    public function setTimer(Timer $timer): BenchmarkFunction
142
    {
143 2
        $this->timer = $timer;
144 2
        return $this;
145
    }
146
147
    /**
148
     * @return null|\Throwable
149
     */
150 2
    public function getException(): ?\Throwable
151
    {
152 2
        return $this->exception;
153
    }
154
155
    /**
156
     * @param \Throwable $exception
157
     * @return BenchmarkFunction
158
     */
159 1
    public function setException(\Throwable $exception): BenchmarkFunction
160
    {
161 1
        $this->exception = $exception;
162 1
        return $this;
163
    }
164
165
}
166