1 | <?php |
||
18 | class Experiment |
||
19 | { |
||
20 | /** |
||
21 | * Experiment name. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $name; |
||
26 | |||
27 | /** |
||
28 | * The control callback. |
||
29 | * |
||
30 | * @var callable |
||
31 | */ |
||
32 | protected $control; |
||
33 | |||
34 | /** |
||
35 | * Context for the control. |
||
36 | * |
||
37 | * @var mixed |
||
38 | */ |
||
39 | protected $controlContext; |
||
40 | |||
41 | /** |
||
42 | * Arguments for the control. |
||
43 | * |
||
44 | * @var mixed |
||
45 | */ |
||
46 | protected $controlArguments; |
||
47 | |||
48 | /** |
||
49 | * Trial callbacks. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $trials = []; |
||
54 | |||
55 | /** |
||
56 | * Parameters for our callbacks. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $params = []; |
||
61 | |||
62 | /** |
||
63 | * Laboratory instance. |
||
64 | * |
||
65 | * @var \Scientist\Laboratory |
||
66 | */ |
||
67 | protected $laboratory; |
||
68 | |||
69 | /** |
||
70 | * Matcher for experiment values. |
||
71 | * |
||
72 | * @var \Scientist\Matchers\Matcher |
||
73 | 21 | */ |
|
74 | protected $matcher; |
||
75 | 21 | ||
76 | 21 | /** |
|
77 | 21 | * Execution chance. |
|
78 | 21 | * |
|
79 | * @var \Scientist\Chances\Chance |
||
80 | */ |
||
81 | protected $chance; |
||
82 | |||
83 | /** |
||
84 | * Create a new experiment. |
||
85 | 12 | * |
|
86 | * @param string $name |
||
87 | 12 | * @param \Scientist\Laboratory $laboratory |
|
88 | */ |
||
89 | public function __construct($name, Laboratory $laboratory) |
||
96 | |||
97 | 1 | /** |
|
98 | * Fetch the experiment name. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | public function getName() |
||
106 | |||
107 | 14 | /** |
|
108 | * Retrieve the laboratory instance. |
||
109 | 14 | * |
|
110 | * @return \Scientist\Laboratory|null |
||
111 | 14 | */ |
|
112 | public function getLaboratory() |
||
116 | |||
117 | /** |
||
118 | * Register a control callback. |
||
119 | 14 | * |
|
120 | * @param callable $callback |
||
121 | 14 | * @param mixed $context |
|
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | public function control(callable $callback, $context = null, $arguments = []) |
||
133 | |||
134 | 12 | /** |
|
135 | * Fetch the control callback. |
||
136 | 12 | * |
|
137 | * @return callable |
||
138 | */ |
||
139 | public function getControl() |
||
143 | |||
144 | public function getControlContext() |
||
148 | 2 | ||
149 | /** |
||
150 | * Fetch the arguments to use with the control callback. |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | public function getControlArguments(): array |
||
158 | 12 | ||
159 | /** |
||
160 | * Register a trial callback. |
||
161 | * |
||
162 | * @param string $name |
||
163 | * @param callable $callback |
||
164 | * |
||
165 | * @return $this |
||
166 | */ |
||
167 | public function trial($name, callable $callback, $context = null, $arguments = []) |
||
173 | |||
174 | /** |
||
175 | * Fetch a trial callback by name. |
||
176 | * |
||
177 | * @param string $name |
||
178 | * |
||
179 | * @return mixed |
||
180 | 12 | */ |
|
181 | public function getTrial($name) |
||
185 | |||
186 | /** |
||
187 | * Fetch an array of trial callbacks. |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | public function getTrials() |
||
195 | |||
196 | 2 | /** |
|
197 | * Set a matcher for this experiment. |
||
198 | * |
||
199 | * @param \Scientist\Matchers\Matcher $matcher |
||
200 | * |
||
201 | * @return $this |
||
202 | */ |
||
203 | public function matcher(Matcher $matcher) |
||
209 | |||
210 | /** |
||
211 | * Get the matcher for this experiment. |
||
212 | * |
||
213 | * @return \Scientist\Matchers\Matcher |
||
214 | 6 | */ |
|
215 | public function getMatcher() |
||
219 | |||
220 | /** |
||
221 | * Set the execution chance. |
||
222 | * |
||
223 | * @param Chances\Chance $chance |
||
224 | 13 | * |
|
225 | * @return $this |
||
226 | 13 | */ |
|
227 | public function chance(Chance $chance) |
||
233 | |||
234 | 6 | /** |
|
235 | * Get the execution chance. |
||
236 | 6 | * |
|
237 | * @return Chances\Chance |
||
238 | 6 | */ |
|
239 | public function getChance() |
||
243 | |||
244 | /** |
||
245 | * Determine whether an experiment should run based on chance. |
||
246 | 3 | * |
|
247 | * @return boolean |
||
248 | 3 | */ |
|
249 | public function shouldRun() |
||
254 | |||
255 | /** |
||
256 | * Get the experiment parameters. |
||
257 | * |
||
258 | * @return array |
||
259 | */ |
||
260 | public function getParams() |
||
264 | |||
265 | /** |
||
266 | * Execute the experiment within the laboratory. |
||
267 | * |
||
268 | * @return mixed |
||
269 | */ |
||
270 | public function run() |
||
276 | |||
277 | /** |
||
278 | * Execute the experiment and return a report. |
||
279 | * |
||
280 | * @return \Scientist\Report |
||
281 | */ |
||
282 | public function report() |
||
288 | } |
||
289 |