Completed
Pull Request — master (#8)
by Jeremy
04:54
created

Study   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 211
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 94.12%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 211
wmc 19
lcom 2
cbo 3
ccs 48
cts 51
cp 0.9412
rs 10

18 Methods

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