|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Scientist; |
|
5
|
|
|
|
|
6
|
|
|
use Scientist\Blind\Preparation; |
|
7
|
|
|
use Scientist\Matchers\StandardMatcher; |
|
8
|
|
|
|
|
9
|
|
|
class Study |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Experiment name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The control instance. |
|
20
|
|
|
* |
|
21
|
|
|
* @var mixed |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $control; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Trial instances. |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $trials = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Laboratory instance. |
|
34
|
|
|
* |
|
35
|
|
|
* @var \Scientist\Laboratory|null |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $laboratory; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Matcher for experiment values. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \Scientist\Matchers\Matcher |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $matcher; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Execution chance. |
|
48
|
|
|
* |
|
49
|
|
|
* @var integer |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $chance = 100; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var Experiment[] |
|
55
|
|
|
*/ |
|
56
|
|
|
protected $experiments = []; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Study constructor. |
|
60
|
|
|
* @param string $name |
|
61
|
|
|
* @param null|Laboratory $laboratory |
|
62
|
|
|
*/ |
|
63
|
20 |
|
public function __construct($name, $laboratory = null) |
|
64
|
|
|
{ |
|
65
|
20 |
|
$this->name = $name; |
|
66
|
20 |
|
$this->laboratory = $laboratory; |
|
67
|
20 |
|
$this->matcher = new StandardMatcher; |
|
68
|
20 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
15 |
|
public function getName() |
|
74
|
|
|
{ |
|
75
|
15 |
|
return $this->name; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return mixed |
|
80
|
|
|
*/ |
|
81
|
6 |
|
public function getControl() |
|
82
|
|
|
{ |
|
83
|
6 |
|
return $this->control; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param mixed $control |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
6 |
|
public function control($control) |
|
91
|
|
|
{ |
|
92
|
6 |
|
$this->control = $control; |
|
93
|
6 |
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return array |
|
98
|
|
|
*/ |
|
99
|
7 |
|
public function getTrials() |
|
100
|
|
|
{ |
|
101
|
7 |
|
return $this->trials; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $name |
|
106
|
|
|
* @return mixed |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function getTrial($name) |
|
109
|
|
|
{ |
|
110
|
1 |
|
return $this->trials[$name]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param string $name |
|
115
|
|
|
* @param mixed $trial |
|
116
|
|
|
* @return $this |
|
117
|
|
|
*/ |
|
118
|
7 |
|
public function trial($name, $trial) |
|
119
|
|
|
{ |
|
120
|
7 |
|
$this->trials[$name] = $trial; |
|
121
|
7 |
|
return $this; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return null|Laboratory |
|
126
|
|
|
*/ |
|
127
|
11 |
|
public function getLaboratory() |
|
128
|
|
|
{ |
|
129
|
11 |
|
return $this->laboratory; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param null|Laboratory $laboratory |
|
134
|
|
|
*/ |
|
135
|
1 |
|
public function setLaboratory($laboratory) |
|
136
|
|
|
{ |
|
137
|
1 |
|
$this->laboratory = $laboratory; |
|
138
|
1 |
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @return Matchers\Matcher |
|
142
|
|
|
*/ |
|
143
|
11 |
|
public function getMatcher() |
|
144
|
|
|
{ |
|
145
|
11 |
|
return $this->matcher; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param Matchers\Matcher $matcher |
|
150
|
|
|
*/ |
|
151
|
1 |
|
public function setMatcher($matcher) |
|
152
|
|
|
{ |
|
153
|
1 |
|
$this->matcher = $matcher; |
|
154
|
1 |
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return int |
|
158
|
|
|
*/ |
|
159
|
11 |
|
public function getChance() |
|
160
|
|
|
{ |
|
161
|
11 |
|
return $this->chance; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @param int $chance |
|
166
|
|
|
*/ |
|
167
|
1 |
|
public function setChance($chance) |
|
168
|
|
|
{ |
|
169
|
1 |
|
$this->chance = $chance; |
|
170
|
1 |
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @return Experiment[] |
|
174
|
|
|
*/ |
|
175
|
1 |
|
public function getExperiments() |
|
176
|
|
|
{ |
|
177
|
1 |
|
return $this->experiments; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @param string $name |
|
182
|
|
|
* @return Experiment |
|
183
|
|
|
*/ |
|
184
|
3 |
|
public function getExperiment($name) |
|
185
|
|
|
{ |
|
186
|
3 |
|
return $this->experiments[$name]; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* @param Experiment $experiment |
|
191
|
|
|
*/ |
|
192
|
11 |
|
public function addExperiment(Experiment $experiment) |
|
193
|
|
|
{ |
|
194
|
11 |
|
$this->experiments[$experiment->getName()] = $experiment; |
|
195
|
11 |
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param string ...$interface blind will implement the interfaces specified |
|
199
|
|
|
* @return mixed |
|
200
|
|
|
*/ |
|
201
|
6 |
|
public function blind($interface = null) |
|
202
|
|
|
{ |
|
203
|
6 |
|
$interfaces = func_get_args(); |
|
204
|
6 |
|
if ($interface == null) { |
|
|
|
|
|
|
205
|
3 |
|
array_shift($interfaces); |
|
206
|
3 |
|
} |
|
207
|
|
|
|
|
208
|
6 |
|
$preparation = new Preparation(); |
|
209
|
6 |
|
return $preparation->prepare($this, $this->getControl(), $this->getTrials(), $interfaces); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|