Completed
Push — develop ( b733eb...69cb61 )
by Alec
06:31
created

BenchmarkFunction::getArgs()   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\Traits\GettableName;
11
use function AlecRabbit\brackets;
12
use function AlecRabbit\str_decorate;
13
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...
14
15
/**
16
 * Class BenchmarkFunction
17
 * @package AlecRabbit
18
 * @internal
19
 */
20
class BenchmarkFunction
21
{
22
    use GettableName;
23
24
    /** @var null|string */
25
    private $comment;
26
27
    /** @var int */
28
    private $index;
29
30
    /** @var array */
31
    private $args;
32
33
    /** @var callable */
34
    private $func;
35
36
    /** @var mixed */
37
    private $result;
38
39
    /**
40
     * BenchmarkedFunction constructor.
41
     * @param callable $func
42
     * @param string $name
43
     * @param int $index
44
     * @param array $args
45
     * @param null|string $comment
46
     */
47 2
    public function __construct($func, string $name, int $index, array $args, ?string $comment = null)
48
    {
49 2
        $this->func = $func;
50 2
        $this->comment = $comment;
51 2
        $this->name = $name;
52 2
        $this->index = $index;
53 2
        $this->args = $args;
54 2
    }
55
56
    /**
57
     * @return string
58
     */
59 2
    public function getComment(): string
60
    {
61 2
        return $this->comment ? str_decorate($this->comment, '"') : '';
62
    }
63
64
    /**
65
     * @return int
66
     */
67 2
    public function getIndex(): int
68
    {
69 2
        return $this->index;
70
    }
71
72
    /**
73
     * @return array
74
     */
75 2
    public function getArgs(): array
76
    {
77 2
        return $this->args;
78
    }
79
80
    /**
81
     * @return callable
82
     */
83 2
    public function getFunction(): callable
84
    {
85 2
        return $this->func;
86
    }
87
88 2
    public function getEnumeratedName(): string
89
    {
90
        return
91 2
            brackets((string)$this->index, BRACKETS_ANGLE) . ' ' . $this->name;
92
    }
93
94
    /**
95
     * @return mixed
96
     */
97 1
    public function getResult()
98
    {
99 1
        return $this->result;
100
    }
101
102
    /**
103
     * @param mixed $result
104
     */
105 2
    public function setResult($result): void
106
    {
107 2
        $this->result = $result;
108 2
    }
109
110
    /**
111
     * @return string
112
     */
113 2
    public function getIndexedName(): string
114
    {
115 2
        return sprintf(
116 2
            '⟨%s⟩ %s',
117 2
            $this->getIndex(),
118 2
            $this->getName()
119
        );
120
    }
121
}
122