Completed
Pull Request — master (#8)
by Jeremy
06:08 queued 03:37
created

Study::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
     * @return mixed
81
     */
82 6
    public function getControl()
83
    {
84 6
        return $this->control;
85
    }
86
87
    /**
88
     * @param mixed $control
89
     * @return $this
90
     */
91 6
    public function control($control)
92
    {
93 6
        $this->control = $control;
94 6
        return $this;
95
    }
96
97
    /**
98
     * @return array
99
     */
100 7
    public function getTrials()
101
    {
102 7
        return $this->trials;
103
    }
104
105
    /**
106
     * @param string $name
107
     * @return mixed
108
     */
109 1
    public function getTrial($name)
110
    {
111 1
        return $this->trials[$name];
112
    }
113
114
    /**
115
     * @param string $name
116
     * @param mixed $trial
117
     * @return $this
118
     */
119 7
    public function trial($name, $trial)
120
    {
121 7
        $this->trials[$name] = $trial;
122 7
        return $this;
123
    }
124
125
    /**
126
     * @return null|Laboratory
127
     */
128 11
    public function getLaboratory()
129
    {
130 11
        return $this->laboratory;
131
    }
132
133
    /**
134
     * @param null|Laboratory $laboratory
135
     */
136 1
    public function setLaboratory($laboratory)
137
    {
138 1
        $this->laboratory = $laboratory;
139 1
    }
140
141
    /**
142
     * @return Matchers\Matcher
143
     */
144 11
    public function getMatcher()
145
    {
146 11
        return $this->matcher;
147
    }
148
149
    /**
150
     * @param Matchers\Matcher $matcher
151
     */
152 1
    public function setMatcher($matcher)
153
    {
154 1
        $this->matcher = $matcher;
155 1
    }
156
157
    /**
158
     * @return int
159
     */
160 11
    public function getChance()
161
    {
162 11
        return $this->chance;
163
    }
164
165
    /**
166
     * @param int $chance
167
     */
168 1
    public function setChance($chance)
169
    {
170 1
        $this->chance = $chance;
171 1
    }
172
173
    /**
174
     * @return Experiment[]
175
     */
176 1
    public function getExperiments()
177
    {
178 1
        return $this->experiments;
179
    }
180
181
    /**
182
     * @param string $name
183
     * @return Experiment
184
     */
185 3
    public function getExperiment($name)
186
    {
187 3
        return $this->experiments[$name];
188
    }
189
190
    /**
191
     * @param Experiment $experiment
192
     */
193 11
    public function addExperiment(Experiment $experiment)
194
    {
195 11
        $this->experiments[$experiment->getName()] = $experiment;
196 11
    }
197
198
    /**
199
     * @param string ...$interface blind will implement the interfaces specified
200
     * @return mixed
201
     */
202 6
    public function blind($interface = null)
203
    {
204 6
        $interfaces = func_get_args();
205 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...
206 3
            array_shift($interfaces);
207 3
        }
208
209 6
        $preparation = new Preparation();
210 6
        return $preparation->prepare($this, $this->getControl(), $this->getTrials(), $interfaces);
211
    }
212
}