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

StandardChance   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldRun() 0 10 2
A getPercentage() 0 4 1
A setPercentage() 0 6 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