Completed
Pull Request — master (#14)
by Steve
02:24
created

Result::setEchoValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Scientist;
4
5
use Exception;
6
7
/**
8
 * Class Execution
9
 *
10
 * An execution records the state of a callback, including how long it
11
 * took to execute, and what values were returned.
12
 *
13
 * @package \Scientist
14
 */
15
class Result
16
{
17
    /**
18
     * Callback result value.
19
     *
20
     * @var mixed
21
     */
22
    protected $value;
23
24
    /**
25
     * The time the callback was executed.
26
     *
27
     * @var float
28
     */
29
    protected $startTime;
30
31
    /**
32
     * The time the callback finished executing.
33
     *
34
     * @var float
35
     */
36
    protected $endTime;
37
38
    /**
39
     * The memory usage before the callback is executed.
40
     *
41
     * @var float
42
     */
43
    protected $startMemory;
44
45
    /**
46
     * The memory usage after the callback is executed.
47
     *
48
     * @var float
49
     */
50
    protected $endMemory;
51
52
    /**
53
     * Exception thrown by callback.
54
     *
55
     * @var \Exception|null
56
     */
57
    protected $exception;
58
59
    /**
60
     * Does the callback result value match the control.
61
     *
62
     * @var boolean
63
     */
64
    protected $match = false;
65
66
    /**
67
     * Anything 'echo'ed out by the experiment.
68
     *
69
     * @var string
70
     */
71
    protected $echoValue;
72
73
    /**
74
     * Get the callback result value.
75
     *
76
     * @return mixed
77
     */
78 15
    public function getValue()
79
    {
80 15
        return $this->value;
81
    }
82
83
    /**
84
     * Set the callback result value.
85
     *
86
     * @param mixed $value
87
     *
88
     * @return $this
89
     */
90 20
    public function setValue($value)
91
    {
92 20
        $this->value = $value;
93
94 20
        return $this;
95
    }
96
97
    /**
98
     * Get the callback execution start time.
99
     *
100
     * @return float
101
     */
102 3
    public function getStartTime()
103
    {
104 3
        return $this->startTime;
105
    }
106
107
    /**
108
     * Set the callback execution start time.
109
     *
110
     * @param float $startTime
111
     *
112
     * @return $this
113
     */
114 21
    public function setStartTime($startTime)
115
    {
116 21
        $this->startTime = $startTime;
117
118 21
        return $this;
119
    }
120
121
    /**
122
     * Get the callback execution end time.
123
     *
124
     * @return float
125
     */
126 3
    public function getEndTime()
127
    {
128 3
        return $this->endTime;
129
    }
130
131
    /**
132
     * Set the callback execution end time.
133
     *
134
     * @param float $endTime
135
     *
136
     * @return $this
137
     */
138 21
    public function setEndTime($endTime)
139
    {
140 21
        $this->endTime = $endTime;
141
142 21
        return $this;
143
    }
144
145
    /**
146
     * Get the execution time of the callback.
147
     *
148
     * @return float
149
     */
150 2
    public function getTime()
151
    {
152 2
        return $this->endTime - $this->startTime;
153
    }
154
155
    /**
156
     * Get the callback execution starting memory usage.
157
     *
158
     * @return float
159
     */
160 3
    public function getStartMemory()
161
    {
162 3
        return $this->startMemory;
163
    }
164
165
    /**
166
     * Set the callback execution starting memory usage.
167
     *
168
     * @param float $startMemory
169
     *
170
     * @return $this
171
     */
172 21
    public function setStartMemory($startMemory)
173
    {
174 21
        $this->startMemory = $startMemory;
175
176 21
        return $this;
177
    }
178
179
    /**
180
     * Get the callback execution ending memory usage.
181
     *
182
     * @return float
183
     */
184 3
    public function getEndMemory()
185
    {
186 3
        return $this->endMemory;
187
    }
188
189
    /**
190
     * Set the callback execution ending memory usage.
191
     *
192
     * @param float $endMemory
193
     *
194
     * @return $this
195
     */
196 21
    public function setEndMemory($endMemory)
197
    {
198 21
        $this->endMemory = $endMemory;
199
200 21
        return $this;
201
    }
202
203
    /**
204
     * Get the memory spike amount of the callback.
205
     *
206
     * @return float
207
     */
208 2
    public function getMemory()
209
    {
210 2
        return $this->endMemory - $this->startMemory;
211
    }
212
213
    /**
214
     * Get the exception thrown by the callback.
215
     *
216
     * @return Exception|null
217
     */
218 3
    public function getException()
219
    {
220 3
        return $this->exception;
221
    }
222
223
    /**
224
     * Set the exception thrown by the callback.
225
     *
226
     * @param Exception|null $exception
227
     *
228
     * @return $this
229
     */
230 3
    public function setException($exception)
231
    {
232 3
        $this->exception = $exception;
233
234 3
        return $this;
235
    }
236
237
    /**
238
     * Determine whether the callback result matches the control.
239
     *
240
     * @return boolean
241
     */
242 6
    public function isMatch()
243
    {
244 6
        return $this->match;
245
    }
246
247
    /**
248
     * Set whether the callback result matches the control.
249
     *
250
     * @param boolean $match
251
     *
252
     * @return $this
253
     */
254 4
    public function setMatch($match)
255
    {
256 4
        $this->match = $match;
257
258 4
        return $this;
259
    }
260
261
    /**
262
     * Returns the value of any output that occurred during executing the
263
     * callback.
264
     *
265
     * @return string
266
     */
267 2
    public function getEchoValue()
268
    {
269 2
        return $this->echoValue;
270
    }
271
272
    /**
273
     * Sets the value of any output that occurred during executing the
274
     * callback.
275
     *
276
     * @param string $value
277
     *
278
     * @return $this
279
     */
280 19
    public function setEchoValue($value)
281
    {
282 19
        $this->echoValue = $value;
283 19
        return $this;
284
    }
285
}
286