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 | public function getControlArguments() |
||
153 | |||
154 | /** |
||
155 | * Register a trial callback. |
||
156 | 12 | * |
|
157 | * @param string $name |
||
158 | 12 | * @param callable $callback |
|
159 | * |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function trial($name, callable $callback, $context = null, $arguments = []) |
||
168 | 1 | ||
169 | /** |
||
170 | 1 | * Fetch a trial callback by name. |
|
171 | * |
||
172 | 1 | * @param string $name |
|
173 | * |
||
174 | * @return mixed |
||
175 | */ |
||
176 | public function getTrial($name) |
||
180 | 12 | ||
181 | /** |
||
182 | 12 | * Fetch an array of trial callbacks. |
|
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | public function getTrials() |
||
190 | |||
191 | /** |
||
192 | 2 | * Set a matcher for this experiment. |
|
193 | * |
||
194 | 2 | * @param \Scientist\Matchers\Matcher $matcher |
|
195 | * |
||
196 | 2 | * @return $this |
|
197 | */ |
||
198 | public function matcher(Matcher $matcher) |
||
204 | 1 | ||
205 | /** |
||
206 | 1 | * Get the matcher for this experiment. |
|
207 | * |
||
208 | * @return \Scientist\Matchers\Matcher |
||
209 | */ |
||
210 | public function getMatcher() |
||
214 | 6 | ||
215 | /** |
||
216 | 6 | * Set the execution chance. |
|
217 | * |
||
218 | * @param Chances\Chance $chance |
||
219 | * |
||
220 | * @return $this |
||
221 | */ |
||
222 | public function chance(Chance $chance) |
||
228 | |||
229 | /** |
||
230 | * Get the execution chance. |
||
231 | * |
||
232 | * @return Chances\Chance |
||
233 | */ |
||
234 | 6 | public function getChance() |
|
238 | 6 | ||
239 | /** |
||
240 | * Determine whether an experiment should run based on chance. |
||
241 | * |
||
242 | * @return boolean |
||
243 | */ |
||
244 | public function shouldRun() |
||
249 | |||
250 | 3 | /** |
|
251 | * Get the experiment parameters. |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | public function getParams() |
||
259 | |||
260 | /** |
||
261 | * Execute the experiment within the laboratory. |
||
262 | * |
||
263 | * @return mixed |
||
264 | */ |
||
265 | public function run() |
||
271 | |||
272 | /** |
||
273 | * Execute the experiment and return a report. |
||
274 | * |
||
275 | * @return \Scientist\Report |
||
276 | */ |
||
277 | public function report() |
||
283 | } |
||
284 |