Test Setup Failed
Pull Request — master (#22)
by Dayle
05:14
created

StandardChance::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
namespace Scientist\Chances;
3
4
class StandardChance implements Chance
5
{
6
    private $percentage = 100;
7
8
    /**
9
     * Determine whether or not the experiment should run
10
     */
11
    public function shouldRun()
12
    {
13
        if ($this->percentage == 0) {
14
            return false;
15
        }
16
17
        $random = random_int(0, 100);
18
19
        return $random <= $this->percentage;
20
    }
21
22
    /**
23
     * @return int
24
     */
25
    public function getPercentage()
26
    {
27
        return $this->percentage;
28
    }
29
30
    /**
31
     * @param int $percentage
32
     * @return $this
33
     */
34
    public function setPercentage($percentage)
35
    {
36
        $this->percentage = $percentage;
37
        
38
        return $this;
39
    }
40
}
41